yet more reorganization

This commit is contained in:
wires 2025-03-05 11:15:54 -05:00
parent f188a0332d
commit 940179bea5
Signed by: wires
SSH key fingerprint: SHA256:9GtP+M3O2IivPDlw1UY872UPUuJH2gI0yG6ExBxaaiM
4 changed files with 4 additions and 116 deletions

View file

@ -2,7 +2,7 @@ local modules = {
'editor',
'plugins_init',
'commands',
'lsp',
'lsp.diagnostics',
-- load mappings only after editor configs are loaded
'mappings',
}

View file

@ -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

View file

@ -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)

View file

@ -1,4 +0,0 @@
require('lsp.diagnostics')
require('lsp.commands')
-- LSP server initialization can be found in mason-lspconfig setup