diff --git a/init.lua b/init.lua index f7a980e..4695ea0 100644 --- a/init.lua +++ b/init.lua @@ -2,7 +2,7 @@ local modules = { 'editor', 'plugins_init', 'commands', - 'lsp', + 'lsp.diagnostics', -- load mappings only after editor configs are loaded 'mappings', } diff --git a/lua/lsp/commands.lua b/lua/lsp/commands.lua deleted file mode 100644 index 2893fcc..0000000 --- a/lua/lsp/commands.lua +++ /dev/null @@ -1,107 +0,0 @@ -local config = require('config') - -local found = false -for _, plugin in ipairs(config.add_plugins) do - if plugin[1] == 'pmizio/typescript-tools.nvim' then - found = true - break - end -end - -if found then - -- Major props to @failen here - -- https://github.com/pmizio/typescript-tools.nvim/issues/124 - vim.api.nvim_create_user_command('NxInit', function() - local now = tostring(os.time()) - local fileName = string.format('%s_graph.json', now) - -- @TODO check if we should use yarn or npx - local cmd = string.format('yarn -s nx graph --file=%s', fileName) - - local function handle_response(_, code) - -- read the file into memory - local projectGraphFile = io.open(fileName, 'r') - if projectGraphFile then - -- read project graph from file - local projectGraph = vim.json.decode(projectGraphFile:read('*a')) - projectGraphFile:close() - - -- remove the graph file - os.remove(fileName) - - -- get typescript-tools lsp client - local lspClients = vim.lsp.get_clients() - local tsclient - for _, client in ipairs(lspClients) do - if client.name == 'typescript-tools' then - tsclient = client - end - end - if not tsclient then - print('typescript-tools.nvim not active') - return - end - - -- get workspace root - -- always first? alternatives to get absolute workspace root? - local workspacePath = tsclient.config.workspace_folders[1].name - if not workspacePath then - print('Could not figure out workspace path') - return - end - - -- create external files for monodon - local externalFiles = {} - for _, project in pairs(projectGraph.graph.nodes) do - local sourceRoot = project.data.sourceRoot - - -- skip the root - if sourceRoot ~= '.' and sourceRoot then - -- localte the entry file. perhaps use tsconfig.[app|lib].json - local mainFile - if - project.data - and project.data.targets - and project.data.targets.build - and project.data.targets.build.options - and project.data.targets.build.options.main - then - mainFile = workspacePath .. '/' .. project.data.targets.build.options.main - else - mainFile = workspacePath .. '/' .. sourceRoot .. '/index.ts' - end - - -- insert to config - table.insert(externalFiles, { - mainFile = mainFile, -- this is not always index.ts! - directory = workspacePath .. '/' .. sourceRoot, - }) - end - end - - -- print(vim.inspect(externalFiles)) - -- send configuration request of monodon plugin to ts_ls - local constants = require('typescript-tools.protocol.constants') - local method = constants.CustomMethods.ConfigurePlugin - local args = { - pluginName = '@monodon/typescript-nx-imports-plugin', - configuration = { - externalFiles = externalFiles, - }, - } - - ---@diagnostic disable-next-line: missing-parameter - tsclient.request(method, args, function() - print('ts_ls handled configuration request', method) - end) - print('NX Plugin initialized!') - end - end - - -- call nx deamon with graph request, run it in the background with job - vim.fn.jobstart(cmd, { - on_exit = handle_response, - stdout_buffered = true, - stderr_buffered = true, - }) - end, {}) -end diff --git a/lua/lsp/diagnostics/init.lua b/lua/lsp/diagnostics.lua similarity index 93% rename from lua/lsp/diagnostics/init.lua rename to lua/lsp/diagnostics.lua index 1fc75cd..9c4d001 100644 --- a/lua/lsp/diagnostics/init.lua +++ b/lua/lsp/diagnostics.lua @@ -1,4 +1,3 @@ -local u = require('utils') local icons = require('utils.icons') local config = require('config') @@ -22,9 +21,9 @@ local function format_diagnostic(diagnostic) return message .. ' ' end -local diagnostic_config = u.merge({ +local diagnostic_config = { underline = true, - update_in_insert = false, + update_in_insert = true, severity_sort = true, signs = { text = { @@ -58,7 +57,7 @@ local diagnostic_config = u.merge({ }, format = format_diagnostic, }, -}, config.diagnostic or {}) +} -- set up diagnostics vim.diagnostic.config(diagnostic_config) diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua deleted file mode 100644 index 823f391..0000000 --- a/lua/lsp/init.lua +++ /dev/null @@ -1,4 +0,0 @@ -require('lsp.diagnostics') -require('lsp.commands') - --- LSP server initialization can be found in mason-lspconfig setup