Skip to content

Commit

Permalink
Make sure csharp-ls find and load solution under project path.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Jun 9, 2024
1 parent e5cf0b7 commit da7d225
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
19 changes: 13 additions & 6 deletions core/lspserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,6 @@ def __init__(self, message_queue, project_path, server_info, server_name, enable
self.save_include_text = False

# Start LSP server.
command_args = self.server_info["command"]
for i, arg in enumerate(command_args):
command_args[i] = replace_template(arg, self.project_path)
self.server_info["command"] = command_args

self.lsp_subprocess = subprocess.Popen(self.server_info["command"],
bufsize=DEFAULT_BUFFER_SIZE,
stdin=PIPE,
Expand Down Expand Up @@ -546,10 +541,22 @@ def send_exit_notification(self):
self.sender.send_notification("exit", {})

def get_server_workspace_change_configuration(self):
return {
settings = {
"settings": self.server_info.get("settings", {})
}

if self.server_info["name"] == "csharp-ls":
# Set settings.csharp.solution if found *.sln file in project,
# to make sure csharp-ls find and load solution with project path, not current path.
settings = {
"settings": {
"csharp": {
"solution": find_csharp_solution_file(self.project_path)
}
}}

return settings

def handle_workspace_configuration_request(self, name, request_id, params):
settings = self.server_info.get("settings", {})

Expand Down
10 changes: 8 additions & 2 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,17 @@ def replace_template(arg, project_path=None):
return arg.replace("%FILEHASH%", os.urandom(21).hex())
elif "%USERPROFILE%" in arg:
return arg.replace("%USERPROFILE%", windows_get_env_value("USERPROFILE"))
elif "%PROJECTPATH%" in arg and project_path:
return arg.replace("%PROJECTPATH%", project_path)
else:
return arg

def find_csharp_solution_file(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".sln"):
return os.path.join(root, file)

return None

def touch(path):
import os

Expand Down
10 changes: 7 additions & 3 deletions langserver/csharp-ls.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"name": "csharp-ls",
"languageId": "c#",
"command": ["$HOME/.dotnet/tools/csharp-ls", "-s", "%PROJECTPATH%"],
"languageId": "csharp",
"command": ["$HOME/.dotnet/tools/csharp-ls"],
"forceInlayHint": true,
"settings": {},
"settings": {
"csharp": {
"solution": null
}
},
"support-single-file": false,
"capabilities": {
"general": {
Expand Down

0 comments on commit da7d225

Please sign in to comment.