Skip to content

Commit 124f22f

Browse files
authored
feat: Add a setting to respect or not respect gitignore during file traversal. (#56)
1 parent c1ffe81 commit 124f22f

File tree

8 files changed

+15
-3
lines changed

8 files changed

+15
-3
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v4
2323

24+
- uses: leafo/gh-actions-lua@v11
25+
- uses: leafo/gh-actions-luarocks@v5
26+
2427
- name: get year month
2528
id: get_date
2629
run: echo "year_month=$(date +'%Y%m')" >> $GITHUB_OUTPUT

README-ja.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ js-i18n.nvim は、JavaScript の i18n ライブラリをサポートする Neov
9494
{
9595
primary_language = {}, -- 優先表示する言語(バーチャルテキストなどの表示に使用する言語の初期設定)
9696
translation_source = { "**/{locales,messages}/*.json" }, -- 翻訳リソースのパターン
97+
respect_gitignore = true, -- 翻訳リソースや実装ファイルを取得する際に .gitignore を尊重するかどうか。false にするど動作が速くなることがあります。
9798
detect_language = ..., -- 言語を検出する関数。デフォルトではファイル名からヒューリスティックに検出する関数が使用されます。
9899
key_separator = ".", -- キーのセパレータ
99100
virt_text = {
@@ -115,3 +116,4 @@ js-i18n.nvim は、JavaScript の i18n ライブラリをサポートする Neov
115116

116117
- ライブラリサポートの強化
117118
- namespace のサポート
119+
- Language Server の実装を別プロジェクトに切り出す

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ The default settings are as follows. For omitted parts, refer to [config.lua](./
9797
{
9898
primary_language = {}, -- The default language to display (initial setting for displaying virtual text, etc.)
9999
translation_source = { "**/{locales,messages}/*.json" }, -- Pattern for translation resources
100+
respect_gitignore = true, -- Whether to respect .gitignore when retrieving translation resources and implementation files. Setting to false may improve performance.
100101
detect_language = ..., -- Function to detect the language. By default, a function that detects the language heuristically from the file name is used.
101102
key_separator = ".", -- Key separator
102103
virt_text = {
@@ -118,3 +119,4 @@ The default settings are as follows. For omitted parts, refer to [config.lua](./
118119

119120
- Enhanced support for libraries
120121
- Namespace support
122+
- Extract the Language Server implementation into a separate project

lua/js-i18n/analyzer.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,13 @@ end
133133
--- @return string[] | nil value カーソルの位置の key
134134
function M.get_key_at_cursor(bufnr, position)
135135
local ts = vim.treesitter
136+
ts.get_parser(bufnr):parse()
136137

137138
-- カーソルの位置のノードを取得
138139
local row = position.line
139140
local col = position.character
140141
local cursor_node = ts.get_node({ bufnr = bufnr, pos = { row, col } })
142+
141143
if cursor_node == nil then
142144
return nil
143145
end

lua/js-i18n/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ end
5454
--- @class I18n.Config
5555
--- @field primary_language string[] 優先表示する言語
5656
--- @field translation_source string[] 翻訳ソースのパターン
57+
--- @field respect_gitignore boolean .gitignore を尊重するかどうか
5758
--- @field detect_language fun(path: string): string ファイルパスから言語を検出する関数
5859
--- @field namespace_separator string?
5960
--- @field key_separator string キーのセパレータ
@@ -81,6 +82,7 @@ local default_config = {
8182
detect_language = M.default_detect_language,
8283
namespace_separator = nil,
8384
key_separator = ".",
85+
respect_gitignore = true,
8486
virt_text = {
8587
enabled = true,
8688
format = default_virt_text_format,

lua/js-i18n/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ i18n.client = nil
3434
i18n.setup = function(opts)
3535
local hl = vim.api.nvim_set_hl
3636

37-
hl(0, '@i18n.translation', { link = 'Comment' })
37+
hl(0, "@i18n.translation", { link = "Comment" })
3838

3939
local group = vim.api.nvim_create_augroup("js-i18n", {})
4040
-- 設定の初期化

lua/js-i18n/reference_table.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local Path = require("plenary.path")
22
local scan = require("plenary.scandir")
33

44
local analyzer = require("js-i18n.analyzer")
5+
local c = require("js-i18n.config")
56
local utils = require("js-i18n.utils")
67

78
local M = {}
@@ -42,7 +43,7 @@ function ReferenceTable:load_all()
4243
end
4344
return entry:match("%.jsx?$") or entry:match("%.tsx?$")
4445
end,
45-
respect_gitignore = true,
46+
respect_gitignore = c.config.respect_gitignore,
4647
on_insert = function(path)
4748
self:load_path(path)
4849
end,

lua/js-i18n/translation_source.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function M.get_translation_files(dir)
3434
end
3535
return entry:match("%.json$")
3636
end,
37-
respect_gitignore = true,
37+
respect_gitignore = c.config.respect_gitignore,
3838
on_insert = function(path)
3939
for _, regexp in ipairs(regexps) do
4040
local match_s = regexp:match_str(path)

0 commit comments

Comments
 (0)