nmoroze / tclint

EDA-centric utility for linting and analyzing Tcl code.
MIT License
30 stars 1 forks source link

Potential of adding an LSP interface #25

Open SethGower opened 7 months ago

SethGower commented 7 months ago

It would be awesome if there were an LSP interface for this program to be able to use the output in editors. I realize this program doesn't do any kind of actual running of the TCL programs or anything, and it might not be able to manage things like "gotoDefinition" and such, but at the very least it could provide Diagnostics in your editor.

As a stopgap measure, I have implemented this in NeoVim with none-ls (previously null-ls) to provide in editor diagnostics when I am working on TCL files. If anyone would like to use my none-ls config for this, it's in my dotfiles

Here is the `none-ls` configuration I wrote to use this I plan on updating this, hopefully to add more information/diagnostic severities based on rules that are violated, but this is a working example. An up to date version can be found [here](https://github.com/SethGower/dotfiles/blob/main/config/nvim/lua/plugins/lsp.lua#L246) ```lua local tcllint = { name = "tclint", method = null_ls.methods.DIAGNOSTICS, filetypes = { "tcl" }, generator = helpers.generator_factory({ command = "tclint", args = function (params) local rv = {} -- check if there is a config file in the root directory, if so -- insert the -c argument with it if vim.fn.filereadable(vim.fn.expand("~/.tcllint.toml")) == 1 then table.insert(rv, '-c=' .. vim.fn.expand("~/.tcllint.toml")) end table.insert(rv, "$FILENAME") return rv end, cwd = nil, check_exit_code = function () return true end, from_stderr = false, ignore_stderr = true, to_stdin = false, to_temp_file = true, format = "line", multiple_files = false, -- TODO: Probably want to rework this so that I can generate actual severity levels for the different types -- of errors/warnings from the output, since it doesn't print "warning" or anything. That might also be -- something to create as a feature request on tclint instead on_output = helpers.diagnostics.from_patterns({ { pattern = [[.*:(%d+):(%d+):%s+(.*)%[(.*)%]$]], groups = { 'row', 'col', 'message', 'code' }, overrides = { severities = { ["ERROR"] = 3, ["WARNING"] = 3, ["INFORMATION"] = 3, ["HINT"] = 4, }, diagnostic = { -- I don't want red everywhere when using this for style checks. Those should be warnings severity = vim.diagnostic.severity.WARN } } } }), }) } ```
nmoroze commented 7 months ago

Thanks for the feature request! Adding LSP support is definitely on the roadmap (which currently exists solely in my head), although isn't a high priority feature right now. I'll probably just keep this issue open as a tracking issue for this if that's alright with you.

Thanks also for sharing your neovim configuration, I just tried it out for myself - it's quite cool!

SethGower commented 7 months ago

Sounds good on keeping this open. I realize it's not a high priority thing, and as I said, I have a working fake LSP thing in the mean time that is working well for me.

FYI: After you closed out #26, here's a patch that I applied to my nvim configuration (pretty much just disable the to_temp_file and enable to_stdin)

diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua
index 6ca4f85..4d3d799 100644
--- a/config/nvim/lua/plugins/lsp.lua
+++ b/config/nvim/lua/plugins/lsp.lua
@@ -263,8 +263,8 @@ M.null_ls = function ()
             check_exit_code = function () return true end,
             from_stderr = false,
             ignore_stderr = true,
-            to_stdin = false,
-            to_temp_file = true,
+            to_stdin = true,
+            to_temp_file = false,
             format = "line",
             multiple_files = false,
             -- TODO: Probably want to rework this so that I can generate actual severity levels for the different types