Bug 507020 - terraform LSP server (terraform-ls) scans whole home directory
Summary: terraform LSP server (terraform-ls) scans whole home directory
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (other bugs)
Version First Reported In: 25.04.3
Platform: Neon Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-14 09:49 UTC by Malte S. Stretz
Modified: 2025-07-22 17:10 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Malte S. Stretz 2025-07-14 09:49:15 UTC
SUMMARY

When I enable the terraform LSP client (terraform-ls) it goes into a frenzy and tries to scan my whole $HOME directory. Span starts to spin up and the Output tabis spammed with logs like the ones posted below.

I wasn't able yet to catch the beginning of that output because even with a `while sleep .1; do killall terraform-ls; done` loop in the background it is just too quick.

STEPS TO REPRODUCE
1. Enable Terraform LSP
2. Open a Terraform file

OBSERVED RESULT
CPU fan starts spinning up, Output window is spammed with logs which indicate that the LSP client tries to scan my .cache directory.

EXPECTED RESULT
A working LSP client.

SOFTWARE/OS VERSIONS
Operating System: KDE neon User Edition
KDE Plasma Version: 6.4.2
KDE Frameworks Version: 6.15.0
Qt Version: 6.9.0
Kernel Version: 6.11.0-29-generic (64-bit)
Graphics Platform: Wayland

ADDITIONAL INFORMATION

Log excerpt:
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/networksecurity} finished
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/notebooks
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/notebooks/@v
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/notebooks/@v} finished
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/notebooks} finished
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/optimization
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/optimization/@v
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/optimization/@v} finished
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/optimization} finished
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orchestration
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orchestration/@v
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orchestration/@v} finished
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orchestration} finished
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orgpolicy
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orgpolicy/@v
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orgpolicy/@v} finished
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/orgpolicy} finished
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/osconfig
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/osconfig/@v
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/osconfig/@v} finished
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/osconfig} finished
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/oslogin
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/oslogin/@v
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/oslogin/@v} finished
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/oslogin} finished
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/phishingprotection
2025/07/14 11:42:55 discover.go:26: bus: -> Discover /home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/phishingprotection/@v
2025/07/14 11:42:55 walker.go:217: walking of {file:///home/ me/.cache/go/pkg/mod/cache/download/cloud.google.com/go/phishingprotection/@v} finished
Comment 1 Malte S. Stretz 2025-07-14 09:50:07 UTC
terraform-ls version:
```
0.35.0
platform: linux/amd64
go: go1.23.2
compiler: gc
```
Comment 2 Malte S. Stretz 2025-07-14 10:05:05 UTC
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.
Comment 3 Malte S. Stretz 2025-07-14 10:16:04 UTC
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!
Comment 4 Malte S. Stretz 2025-07-14 10:37:01 UTC
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}"
    }
```
Comment 5 Waqar Ahmed 2025-07-14 10:55:06 UTC
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.
Comment 6 Waqar Ahmed 2025-07-14 10:58:14 UTC
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": [....]
Comment 7 Waqar Ahmed 2025-07-14 11:01:17 UTC
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
Comment 8 Malte S. Stretz 2025-07-14 12:42:26 UTC
(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.
Comment 9 Waqar Ahmed 2025-07-14 12:49:25 UTC
> * "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
Comment 10 Bug Janitor Service 2025-07-14 13:10:32 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1820
Comment 11 Malte S. Stretz 2025-07-14 13:14:30 UTC
(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).
Comment 12 Waqar Ahmed 2025-07-14 14:05:17 UTC
> 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
Comment 13 Waqar Ahmed 2025-07-14 19:48:44 UTC
Thanks for improving Kate
Comment 14 Malte S. Stretz 2025-07-15 09:35:57 UTC
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
Comment 15 Christoph Cullmann 2025-07-22 17:10:55 UTC
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