Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add default arg to pick compilation database #3649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anirudhsundar
Copy link
Contributor

The tblgen_lsp_server doesn't seem to load any specific compilation database server and hence we need to explicitly specify the command-line argument to pick the correct database path.

@anirudhsundar anirudhsundar requested a review from glepnir as a code owner March 19, 2025 08:55
@anirudhsundar anirudhsundar force-pushed the tablegen_compilation_database_arg branch from 7e8074a to 6654dd2 Compare March 19, 2025 09:13
@@ -1,8 +1,14 @@
local util = require 'lspconfig.util'

local get_compile_commands_path = function()
return '--tablegen-compilation-database='
.. vim.fs.dirname(vim.fs.find('.git', { path = vim.fn.expand('%:p:h'), upward = true })[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is not .git folder what happen here

Copy link
Contributor Author

@anirudhsundar anirudhsundar Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch, I've modified the code to look directly for tablegen_compile_commands.yml file and return an empty string if it is not found so that it falls back to LSP invocation without any arguments.

We don't need to look for a .git at all in this case I think since the compilation commands database file is all that it needs.

@anirudhsundar anirudhsundar force-pushed the tablegen_compilation_database_arg branch 3 times, most recently from 05bb191 to 56b5d2a Compare March 21, 2025 12:21
@anirudhsundar
Copy link
Contributor Author

Friendly ping for review

return '--tablegen-compilation-database=' .. vim.fs.dirname(file) .. '/tablegen_compile_commands.yml'
end

return ''
Copy link
Member

@justinmk justinmk Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will send a literal empty string arg to tblgen-lsp-server, are you sure it handles that? Try this from a shell:

tblgen-lsp-server ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, I did not know that (I'm learning both lua and nvim-lsp as I'm doing this).

tblgen-lsp-server "" doesn't work on the shell, but weirdly enough, I did not get any errors when I tested the LSP on a directory that does not have any tablgen_compile_commands.yml file. Maybe the error was printed in LSP log and I missed it.

Anyway, thanks for the catch. I modified the function to build the whole command instead of just the argument. This new version should definitely work in all cases as far as I can tell.

Let me know if this makes sense, thanks.

The tblgen_lsp_server doesn't seem to load any specific compilation
database server and hence we need to explicitly specify the command-line
argument to pick the correct database path.
@anirudhsundar anirudhsundar force-pushed the tablegen_compilation_database_arg branch from 56b5d2a to b055996 Compare March 25, 2025 17:11
@anirudhsundar
Copy link
Contributor Author

@justinmk @glepnir Is the current version good to be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants