|
@@ -16,32 +16,80 @@ end
|
|
|
if vim.fn.executable("deno") == 1 then
|
|
|
vim.lsp.enable("deno");
|
|
|
else
|
|
|
- require('typescript').setup({
|
|
|
- server = {
|
|
|
- init_options = {
|
|
|
- completionDisableFilterText = true,
|
|
|
- preferences = {
|
|
|
- importModuleSpecifierPreference = 'non-relative',
|
|
|
- -- this prevents renames from aliasing when destructuring
|
|
|
- providePrefixAndSuffixTextForRename = false,
|
|
|
- },
|
|
|
+ vim.lsp.config("ts_ls", {
|
|
|
+ init_options = {
|
|
|
+ completionDisableFilterText = true,
|
|
|
+ preferences = {
|
|
|
+ importModuleSpecifierPreference = 'non-relative',
|
|
|
+ -- this prevents renames from aliasing when destructuring
|
|
|
+ providePrefixAndSuffixTextForRename = false,
|
|
|
},
|
|
|
- handlers = {
|
|
|
- ['$/typescriptVersion'] = function(err, result, ctx, config)
|
|
|
- vim.notify(string.format('Typescript %s', result.version))
|
|
|
+ },
|
|
|
+ handlers = {
|
|
|
+ ['$/typescriptVersion'] = function(err, result, ctx, config)
|
|
|
+ vim.notify(string.format('Typescript %s', result.version))
|
|
|
+ end
|
|
|
+ },
|
|
|
+ flags = {
|
|
|
+ debounce_text_changes = 150,
|
|
|
+ },
|
|
|
+ on_init = function(client)
|
|
|
+ -- mark tsserver as not having formatting available as we rely on
|
|
|
+ -- eslint and dprint for that
|
|
|
+ client.server_capabilities.documentFormattingProvider = false
|
|
|
+ client.server_capabilities.documentRangeFormattingProvider = false
|
|
|
+ end,
|
|
|
+ on_attach = function(client)
|
|
|
+ -- add custom commands, we follow upstream's Lsp* prefix convention
|
|
|
+
|
|
|
+ -- setup custom source actions, unlike code actions these apply to the
|
|
|
+ -- whole file rather than a particular line.
|
|
|
+ local function source_action(usercmd_name, command_name)
|
|
|
+ vim.api.nvim_buf_create_user_command(0, usercmd_name, function()
|
|
|
+ vim.lsp.buf.code_action({
|
|
|
+ context = { only = { command_name } },
|
|
|
+ apply = true,
|
|
|
+ })
|
|
|
+ end, {})
|
|
|
+ end
|
|
|
+
|
|
|
+ source_action("LspAddMissingImports", "source.addMissingImports.ts")
|
|
|
+ source_action("LspOrganizeImports", "source.organizeImports.ts")
|
|
|
+ source_action("LspRemoveUnusedImports", "source.removeUnusedImports.ts")
|
|
|
+
|
|
|
+ -- rename file with import renaming, this does no error checking
|
|
|
+ vim.api.nvim_buf_create_user_command(0, "LspRenameFile", function()
|
|
|
+ local source = vim.api.nvim_buf_get_name(0)
|
|
|
+
|
|
|
+ local function do_rename(target)
|
|
|
+ if target == nil then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ -- rename the buffer
|
|
|
+ vim.lsp.util.rename(source, target)
|
|
|
+
|
|
|
+ -- ask LSP to rename imports
|
|
|
+ client:exec_cmd({
|
|
|
+ command = "_typescript.applyRenameFile",
|
|
|
+ arguments = {
|
|
|
+ {
|
|
|
+ sourceUri = vim.uri_from_fname(source),
|
|
|
+ targetUri = vim.uri_from_fname(target),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
end
|
|
|
- },
|
|
|
- flags = {
|
|
|
- debounce_text_changes = 150,
|
|
|
- },
|
|
|
- on_init = function(client)
|
|
|
- -- mark tsserver as not having formatting available as we rely on
|
|
|
- -- eslint and dprint for that
|
|
|
- client.server_capabilities.documentFormattingProvider = false
|
|
|
- client.server_capabilities.documentRangeFormattingProvider = false
|
|
|
- end,
|
|
|
- }
|
|
|
+
|
|
|
+ vim.ui.input({
|
|
|
+ prompt = "New Filename: ",
|
|
|
+ completion = "file",
|
|
|
+ default = source,
|
|
|
+ }, do_rename)
|
|
|
+ end, {})
|
|
|
+ end,
|
|
|
})
|
|
|
+ vim.lsp.enable("ts_ls")
|
|
|
end
|
|
|
|
|
|
if vim.fn.executable("gopls") == 1 then
|