Summary: | terraform LSP server (terraform-ls) scans whole home directory | ||
---|---|---|---|
Product: | [Applications] kate | Reporter: | Malte S. Stretz <mss> |
Component: | general | Assignee: | KWrite Developers <kwrite-bugs-null> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | waqar.17a |
Priority: | NOR | ||
Version First Reported In: | 25.04.3 | ||
Target Milestone: | --- | ||
Platform: | Neon | ||
OS: | Linux | ||
Latest Commit: | https://invent.kde.org/utilities/kate/-/commit/4c564020b3431447de2602c8eb5a978de68af857 | Version Fixed In: | |
Sentry Crash Report: |
Description
Malte S. Stretz
2025-07-14 09:49:15 UTC
terraform-ls version: ``` 0.35.0 platform: linux/amd64 go: go1.23.2 compiler: gc ``` There is a slightly modified config available at https://github.com/hashicorp/terraform-ls/blob/main/docs/USAGE.md#kate which includes the ``"rootIndicationFileNames": ["*.tf", "*.tfvars"]` options but that doesn't help either. What a fascinating Heisenbug: When I start kate as `env QT_LOGGING_RULES=katelspclientplugin=true kate locals.tf` (cf. https://docs.kde.org/stable5/en/kate/kate/kate-application-plugin-lspclient.html) the issue persists. When I start it as `env QT_LOGGING_RULES=katelspclientplugin=true LSPCLIENT_DEBUG=1 kate locals.tf` (I had to dig up that env variable from the source) the issue is gone! I finally found the output in the journal. And indeed, the rootPath was set to my Home Directory even though the description at https://docs.kde.org/stable5/en/kate/kate/kate-application-plugin-lspclient.html sounds like it should have limited the root to my project folder. I was able to fix this by setting the root explicitly: ``` "terraform": { "command": ["terraform-ls", "serve"], "url": "https://github.com/hashicorp/terraform-ls", "highlightingModeRegex": "^Terraform$", "rootIndicationFileNames": ["*.tf", "*.tfvars"], "root": "%{Project:NativePath}" } ``` Can you paste the full contests of user settings json? The config needs to wrapped in: { "servers": { "terraform": { ... } } } Just like in the builtin settings. Also try to remove rootFileIndicationNames and root. See if the server can work without it. Too late, I see you fixed it already, however I think: "rootIndicationFileNames": ["*.tf", "*.tfvars"], is wrong. Its a pattern, so I believe it should be: "rootIndicationFilePatterns": [....] Thinking again, If the server doesn't work correctly, perhaps we should fix the default config that we ship. Can you confirm it doesn't work with default config? And perhaps you would like to open a merge request and fix it? The default config is here: https://invent.kde.org/utilities/kate/-/blob/master/addons/lspclient/settings.json (In reply to Waqar Ahmed from comment #7) > Thinking again, If the server doesn't work correctly, perhaps we should fix > the default config that we ship. > > Can you confirm it doesn't work with default config? Yes, that's why I raised this issue. I re-read the explanation on https://docs.kde.org/stable5/en/kate/kate/kate-application-plugin-lspclient.html and I think I misunderstood this before. * "root" is only used if given and then the rules as descibed (absolue or relative) apply * "rootIndicationFileNames" only look for files in the *parent* directory which is why it didn't work for me * else it falls back to $HOME as it does here which causes the performance issues I see I haven't tried it yet but I think the best fix for this problem is to set ``` "root": "." ``` to avoid falling back to $HOME. I will rasie a PR for that as suggested. > * "rootIndicationFileNames" only look for files in the *parent* directory which is why it didn't work for me
It looks in all parent directories, it keeps doing `cd ..` till it finds a root indication file. Also it looks for file with exact names. It won't work with `*.tf`. For a pattern, "rootIndicationFilePatterns" should be used
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1820 (In reply to Waqar Ahmed from comment #9) > > * "rootIndicationFileNames" only look for files in the *parent* directory which is why it didn't work for me > > It looks in all parent directories, it keeps doing `cd ..` till it finds a > root indication file. Also it looks for file with exact names. It won't work > with `*.tf`. For a pattern, "rootIndicationFilePatterns" should be used Ah, I just copy and pasted the code from https://github.com/hashicorp/terraform-ls/blob/main/docs/USAGE.md#kate -- looks like the "offical" documentation is broken then. I think `"root": "."` is better though since it will use the project directory, ie a bit more context (cf. PR). > Ah, I just copy and pasted the code from https://github.com/hashicorp/terraform-ls/blob/main/docs/USAGE.md#kate -- looks like the "offical" documentation is broken then.
Yep
Thanks for improving Kate Git commit cb9945e90edc49aee30426eb801f82cb66639458 by Malte Stretz, on behalf of Malte S. Stretz. Committed on 15/07/2025 at 09:06. Pushed by cullmann into branch 'master'. Limit Terraform LSP to project directory The LSP server will scan the root directory recursively so the fallback to $HOME is not a good idea, performance wise. M +1 -0 addons/lspclient/settings.json https://invent.kde.org/utilities/kate/-/commit/cb9945e90edc49aee30426eb801f82cb66639458 Git commit 4c564020b3431447de2602c8eb5a978de68af857 by Christoph Cullmann. Committed on 22/07/2025 at 17:10. Pushed by cullmann into branch 'release/25.08'. Limit Terraform LSP to project directory The LSP server will scan the root directory recursively so the fallback to $HOME is not a good idea, performance wise. (cherry picked from commit cb9945e90edc49aee30426eb801f82cb66639458) Co-authored-by: Malte S. Stretz <mss@apache.org> M +1 -0 addons/lspclient/settings.json https://invent.kde.org/utilities/kate/-/commit/4c564020b3431447de2602c8eb5a978de68af857 |