Bug 499187

Summary: RootUri for LSP, Lua LSP and HOME directory
Product: [Applications] kate Reporter: Daniele Scasciafratte <mte90net>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: waqar.17a
Priority: NOR    
Version First Reported In: 24.12.1   
Target Milestone: ---   
Platform: Debian unstable   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Daniele Scasciafratte 2025-01-27 10:16:24 UTC
SUMMARY
If you have the lua lsp server, a file in the home folder like in my case /home/mte90/.config/nvim/ Kate will use the $HOME as workspace folder and this for the Lua LSP is a problem because it will scan the whole home folder and stops working.

[11:05:46  Git Informazioni] Impossibile trovare la cartella .git per «/home/mte90», le cose potrebbero non funzionare correttamente
[11:05:46  Client LSP Registro] Server avviato lua@/home/mte90: /usr/local/bin/lua-language-server
[11:05:47  Server LSP Registro] lua@/home/mte90
Log path: file:///opt/lua-language-server/log/file_home_mte90.log
[11:05:47  Server LSP Errore] lua@/home/mte90
Your workspace is set to `/home/mte90`. Lua language server refused to load this directory. Please check your configuration.[learn more here](https://luals.github.io/wiki/faq#why-is-the-server-scanning-the-wrong-folder)
[11:05:47  Server LSP Registro] lua@/home/mte90
[Error] Your workspace is set to `/home/mte90`. Lua language server refused to load this directory. Please check your configuration.[learn more here](https://luals.github.io/wiki/faq#why-is-the-server-scanning-the-wrong-folder)

Basically says that in /home/mte90 there is no git folder but is the rootUri sent to the lsp server, their faq https://luals.github.io/wiki/faq/#why-is-the-server-scanning-the-wrong-folder
So ideally I think that in case for LSP servers and something inside the dotfiles in the $HOME directory it should shared the paernt but the folder itself to avoid that issue.
I don't know if the issue exists also with other LSP, maybe others don't do this reports and scans anyway or avoid it. Probably a global behaviour in kate should avoid performance issues.

STEPS TO REPRODUCE
1. Create a lua file inside a dotfiles folder in the $HOME directory
2. Check the diagnostic report 

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 24.12
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Daniele Scasciafratte 2025-01-27 10:22:29 UTC
If I create a .luarc.json file and I put it on /home/mte90 it is used but there is still the error because Kate is sending that parameter anyway.
Comment 2 Waqar Ahmed 2025-01-27 11:13:29 UTC
Does it work better if you add 

            "root": ""

to the lua server settings? (See bash server for example)
Comment 3 Daniele Scasciafratte 2025-01-27 11:16:08 UTC
Nope:

```
"lua": {
            "command": ["lua-language-server"],
            "url": "https://github.com/sumneko/lua-language-server",
            "highlightingModeRegex": "^Lua$",
	"root":""
        }
```

The log output:
```
[12:14:37.959][info] [#0:script/client.lua:657]: Client init	{
  capabilities = {
    textDocument = {
      codeAction = {
        codeActionLiteralSupport = {
          codeActionKind = {
            valueSet = { "quickfix", "refactor", "source" }
          }
        }
      },
      completion = {
        completionItem = {
          resolveSupport = {
            properties = { "additionalTextEdits", "documentation" }
          },
          snippetSupport = true
        }
      },
      documentSymbol = {
        hierarchicalDocumentSymbolSupport = true
      },
      hover = {
        contentFormat = { "markdown", "plaintext" }
      },
      inlayHint = {
        dynamicRegistration = false
      },
      publishDiagnostics = {
        relatedInformation = true
      },
      selectionRange = {
        dynamicRegistration = false
      },
      semanticTokens = {
        formats = { "relative" },
        requests = {
          full = {
            delta = true
          },
          range = true
        },
        tokenModifiers = {},
        tokenTypes = { "namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "keyword", "modifier", "comment", "string", "number", "regexp", "operator" }
      },
      synchronization = {
        didSave = true
      }
    },
    window = {
      showMessage = {
        messageActionItem = {
          additionalPropertiesSupport = true
        }
      },
      workDoneProgress = true
    }
  },
  processId = 101697,
  rootPath = "/home/mte90",
  rootUri = "file:///home/mte90"
}
```
As you can see don't affect the LSP server.
Comment 4 Waqar Ahmed 2025-01-27 11:22:18 UTC
Do you have project plugin enabled?

You can also try to use:
            "rootIndicationFileNames": [".luarc.json"]
where .luarc.json lives at the root of your project. That should work
Comment 5 Daniele Scasciafratte 2025-01-27 11:25:07 UTC
I have the project plugin enabled and also with that parameter I still have the issue.
Comment 6 Waqar Ahmed 2025-01-27 11:39:18 UTC
Ok, then you can have a `.kateproject` file in /home/mte90/.config/nvim/

In that file (/home/mte90/.config/nvim/.kateproject), you can specify the exact root. Contents of the file below

{
    "name": "Neovim_Config",
    "files": [
        {
        "directory": ".",
        "recursive": 1,
        "hidden": 1
        }
    ],
    "exclude_patterns" : [],
    "lspclient": {
        "servers": {
            "lua": {
                "command": ["lua-language-server"],
                "root": "/home/mte90/.config/nvim/",
                "highlightingModeRegex": "^Lua$"
            }
        }
    }
}

Kate will treat /home/mte90/.config/nvim/ as a project folder if this file is present. The folder should appear in the project sidebar with the name Neovim_Config at the top. LSP plugin will then use the absolute path specified in the "root" key.
Comment 7 Daniele Scasciafratte 2025-01-27 11:46:41 UTC
That solution worked.
Comment 8 Bug Janitor Service 2025-02-11 03:46:50 UTC
🐛🧹 ⚠️ This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information, then set the bug status to REPORTED. If there is no change for at least 30 days, it will be automatically closed as RESOLVED WORKSFORME.

For more information about our bug triaging procedures, please read https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging.

Thank you for helping us make KDE software even better for everyone!