Skip to content

Commit

Permalink
feat: simplify config path
Browse files Browse the repository at this point in the history
  • Loading branch information
llllvvuu committed Jul 25, 2023
1 parent 22f454d commit f21fb2f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ require("typescript-tools").setup {
-- described below
tsserver_format_options = {},
tsserver_file_preferences = {},
-- mirror of https://github.com/microsoft/vscode/blob/885dba39a5f546c5077196a8c31b03d03a293b31/extensions/typescript-language-features/package.json#L145-L1266
-- `typescript-tools.nvim` currently only supports `typescript.suggest.completeFunctionCalls`
vscode_configuration = { ["typescript.suggest.completeFunctionCalls"] = true },
-- mirror of VSCode's `typescript.suggest.completeFunctionCalls`
complete_function_calls = false,
},
}
```
Expand Down
11 changes: 4 additions & 7 deletions lua/typescript-tools/config.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
---@see https://github.com/microsoft/vscode/blob/885dba39a5f546c5077196a8c31b03d03a293b31/extensions/typescript-language-features/package.json#L145-L1266
---@alias VsCodeConfiguration { typescript.suggest.completeFunctionCalls: boolean }

---@class Settings
---@field plugin_name string
---@field separate_diagnostic_server boolean
Expand All @@ -11,7 +8,7 @@
---@field tsserver_format_options table|fun(filetype: string): table
---@field tsserver_file_preferences table|fun(filetype: string): table
---@field tsserver_max_memory number|"auto"
---@field vscode_configuration VsCodeConfiguration
---@field complete_function_calls boolean
---@field expose_as_code_action ("fix_all"| "add_missing_imports"| "remove_unused")[]
local M = {}
local __store = {}
Expand Down Expand Up @@ -110,7 +107,7 @@ function M.load_settings(settings)
{ "number", "string" },
true,
},
["settings.vscode_configuration"] = { settings.vscode_configuration, "table", true },
["settings.complete_function_calls"] = { settings.complete_function_calls, "boolean", true },
["settings.expose_as_code_action"] = {
settings.expose_as_code_action,
"table",
Expand Down Expand Up @@ -148,8 +145,8 @@ function M.load_settings(settings)
__store.tsserver_max_memory = "auto"
end

if not settings.vscode_configuration then
__store.vscode_configuration = {}
if not settings.complete_function_calls then
__store.complete_function_calls = false
end

if not settings.expose_as_code_action then
Expand Down
2 changes: 1 addition & 1 deletion lua/typescript-tools/protocol/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function M.should_create_function_snippet(kind, filetype)
local preferences = plugin_config.get_tsserver_file_preferences(filetype)
return preferences.includeCompletionsWithSnippetText
and (kind == c.CompletionItemKind.Function or kind == c.CompletionItemKind.Method)
and plugin_config.vscode_configuration["typescript.suggest.completeFunctionCalls"]
and plugin_config.complete_function_calls
end

return M
14 changes: 6 additions & 8 deletions tests/requests_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ describe("Lsp request", function()
assert.are.same(completions[#completions], "warn")

-- same test as above but with function snippets enabled
local prev_config =
plugin_config.vscode_configuration["typescript.suggest.completeFunctionCalls"]
plugin_config.vscode_configuration["typescript.suggest.completeFunctionCalls"] = true
local prev_config = plugin_config.complete_function_calls
plugin_config.complete_function_calls = true

ret = vim.lsp.buf_request_sync(0, methods.Completion, req)
result = lsp_assert.response(ret)
Expand All @@ -182,7 +181,7 @@ describe("Lsp request", function()
assert.are.same(completions[1], "assert(...)")
assert.are.same(completions[#completions], "warn(...)")

plugin_config.vscode_configuration["typescript.suggest.completeFunctionCalls"] = prev_config
plugin_config.complete_function_calls = prev_config
end)

it("should return correct response for " .. methods.CompletionResolve, function()
Expand Down Expand Up @@ -212,9 +211,8 @@ describe("Lsp request", function()
assert.are.same(result.detail, "(method) Console.warn(...data: any[]): void")

-- same test as above but with function snippets enabled
local prev_config =
plugin_config.vscode_configuration["typescript.suggest.completeFunctionCalls"]
plugin_config.vscode_configuration["typescript.suggest.completeFunctionCalls"] = true
local prev_config = plugin_config.complete_function_calls
plugin_config.complete_function_calls = true

req.label = "warn(...)"
req.insertTextFormat = c.InsertTextFormat.Snippet
Expand All @@ -225,7 +223,7 @@ describe("Lsp request", function()
assert.are.same(result.insertText, "warn($1)$0")
assert.are.same(result.detail, "(method) Console.warn(...data: any[]): void")

plugin_config.vscode_configuration["typescript.suggest.completeFunctionCalls"] = prev_config
plugin_config.complete_function_calls = prev_config
end)

it("should return correct response for " .. methods.SignatureHelp, function()
Expand Down

0 comments on commit f21fb2f

Please sign in to comment.