Add files using upload-large-folder tool
Browse files- projects/ui/serena-new/src/serena/resources/config/contexts/oaicompat-agent.yml +8 -0
- projects/ui/serena-new/src/serena/resources/config/internal_modes/jetbrains.yml +15 -0
- projects/ui/serena-new/src/serena/resources/config/modes/editing.yml +112 -0
- projects/ui/serena-new/src/serena/resources/config/modes/interactive.yml +11 -0
- projects/ui/serena-new/src/serena/resources/config/modes/mode.template.yml +7 -0
- projects/ui/serena-new/src/serena/resources/config/modes/no-onboarding.yml +8 -0
- projects/ui/serena-new/src/serena/resources/config/modes/onboarding.yml +16 -0
- projects/ui/serena-new/src/serena/resources/config/modes/one-shot.yml +15 -0
- projects/ui/serena-new/src/serena/resources/config/modes/planning.yml +15 -0
- projects/ui/serena-new/src/serena/resources/config/prompt_templates/simple_tool_outputs.yml +75 -0
- projects/ui/serena-new/src/serena/resources/config/prompt_templates/system_prompt.yml +66 -0
- projects/ui/serena-new/src/solidlsp/language_servers/bash_language_server.py +230 -0
- projects/ui/serena-new/src/solidlsp/language_servers/clangd_language_server.py +210 -0
- projects/ui/serena-new/src/solidlsp/language_servers/clojure_lsp.py +220 -0
- projects/ui/serena-new/src/solidlsp/language_servers/common.py +114 -0
- projects/ui/serena-new/src/solidlsp/language_servers/csharp_language_server.py +741 -0
- projects/ui/serena-new/src/solidlsp/language_servers/dart_language_server.py +158 -0
- projects/ui/serena-new/src/solidlsp/language_servers/eclipse_jdtls.py +723 -0
- projects/ui/serena-new/src/solidlsp/language_servers/erlang_language_server.py +230 -0
- projects/ui/serena-new/src/solidlsp/language_servers/gopls.py +159 -0
projects/ui/serena-new/src/serena/resources/config/contexts/oaicompat-agent.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: All tools except InitialInstructionsTool for agent context, uses OpenAI compatible tool definitions
|
| 2 |
+
prompt: |
|
| 3 |
+
You are running in agent context where the system prompt is provided externally. You should use symbolic
|
| 4 |
+
tools when possible for code understanding and modification.
|
| 5 |
+
excluded_tools:
|
| 6 |
+
- initial_instructions
|
| 7 |
+
|
| 8 |
+
tool_description_overrides: {}
|
projects/ui/serena-new/src/serena/resources/config/internal_modes/jetbrains.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: JetBrains tools replace language server-based tools
|
| 2 |
+
prompt: |
|
| 3 |
+
You have access to the very powerful JetBrains tools for symbolic operations:
|
| 4 |
+
* `jet_brains_find_symbol` replaces `find_symbol`
|
| 5 |
+
* `jet_brains_find_referencing_symbols` replaces `find_referencing_symbols`
|
| 6 |
+
* `jet_brains_get_symbols_overview` replaces `get_symbols_overview`
|
| 7 |
+
excluded_tools:
|
| 8 |
+
- find_symbol
|
| 9 |
+
- find_referencing_symbols
|
| 10 |
+
- get_symbols_overview
|
| 11 |
+
- restart_language_server
|
| 12 |
+
included_optional_tools:
|
| 13 |
+
- jet_brains_find_symbol
|
| 14 |
+
- jet_brains_find_referencing_symbols
|
| 15 |
+
- jet_brains_get_symbols_overview
|
projects/ui/serena-new/src/serena/resources/config/modes/editing.yml
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: All tools, with detailed instructions for code editing
|
| 2 |
+
prompt: |
|
| 3 |
+
You are operating in editing mode. You can edit files with the provided tools
|
| 4 |
+
to implement the requested changes to the code base while adhering to the project's code style and patterns.
|
| 5 |
+
Use symbolic editing tools whenever possible for precise code modifications.
|
| 6 |
+
If no editing task has yet been provided, wait for the user to provide one.
|
| 7 |
+
|
| 8 |
+
When writing new code, think about where it belongs best. Don't generate new files if you don't plan on actually
|
| 9 |
+
integrating them into the codebase, instead use the editing tools to insert the code directly into the existing files in that case.
|
| 10 |
+
|
| 11 |
+
You have two main approaches for editing code - editing by regex and editing by symbol.
|
| 12 |
+
The symbol-based approach is appropriate if you need to adjust an entire symbol, e.g. a method, a class, a function, etc.
|
| 13 |
+
But it is not appropriate if you need to adjust just a few lines of code within a symbol, for that you should
|
| 14 |
+
use the regex-based approach that is described below.
|
| 15 |
+
|
| 16 |
+
Let us first discuss the symbol-based approach.
|
| 17 |
+
Symbols are identified by their name path and relative file path, see the description of the `find_symbol` tool for more details
|
| 18 |
+
on how the `name_path` matches symbols.
|
| 19 |
+
You can get information about available symbols by using the `get_symbols_overview` tool for finding top-level symbols in a file,
|
| 20 |
+
or by using `find_symbol` if you already know the symbol's name path. You generally try to read as little code as possible
|
| 21 |
+
while still solving your task, meaning you only read the bodies when you need to, and after you have found the symbol you want to edit.
|
| 22 |
+
Before calling symbolic reading tools, you should have a basic understanding of the repository structure that you can get from memories
|
| 23 |
+
or by using the `list_dir` and `find_file` tools (or similar).
|
| 24 |
+
For example, if you are working with python code and already know that you need to read the body of the constructor of the class Foo, you can directly
|
| 25 |
+
use `find_symbol` with the name path `Foo/__init__` and `include_body=True`. If you don't know yet which methods in `Foo` you need to read or edit,
|
| 26 |
+
you can use `find_symbol` with the name path `Foo`, `include_body=False` and `depth=1` to get all (top-level) methods of `Foo` before proceeding
|
| 27 |
+
to read the desired methods with `include_body=True`.
|
| 28 |
+
In particular, keep in mind the description of the `replace_symbol_body` tool. If you want to add some new code at the end of the file, you should
|
| 29 |
+
use the `insert_after_symbol` tool with the last top-level symbol in the file. If you want to add an import, often a good strategy is to use
|
| 30 |
+
`insert_before_symbol` with the first top-level symbol in the file.
|
| 31 |
+
You can understand relationships between symbols by using the `find_referencing_symbols` tool. If not explicitly requested otherwise by a user,
|
| 32 |
+
you make sure that when you edit a symbol, it is either done in a backward-compatible way, or you find and adjust the references as needed.
|
| 33 |
+
The `find_referencing_symbols` tool will give you code snippets around the references, as well as symbolic information.
|
| 34 |
+
You will generally be able to use the info from the snippets and the regex-based approach to adjust the references as well.
|
| 35 |
+
You can assume that all symbol editing tools are reliable, so you don't need to verify the results if the tool returns without error.
|
| 36 |
+
|
| 37 |
+
{% if 'replace_regex' in available_tools %}
|
| 38 |
+
Let us discuss the regex-based approach.
|
| 39 |
+
The regex-based approach is your primary tool for editing code whenever replacing or deleting a whole symbol would be a more expensive operation.
|
| 40 |
+
This is the case if you need to adjust just a few lines of code within a method, or a chunk that is much smaller than a whole symbol.
|
| 41 |
+
You use other tools to find the relevant content and
|
| 42 |
+
then use your knowledge of the codebase to write the regex, if you haven't collected enough information of this content yet.
|
| 43 |
+
You are extremely good at regex, so you never need to check whether the replacement produced the correct result.
|
| 44 |
+
In particular, you know what to escape and what not to escape, and you know how to use wildcards.
|
| 45 |
+
Also, the regex tool never adds any indentation (contrary to the symbolic editing tools), so you have to take care to add the correct indentation
|
| 46 |
+
when using it to insert code.
|
| 47 |
+
Moreover, the replacement tool will fail if it can't perform the desired replacement, and this is all the feedback you need.
|
| 48 |
+
Your overall goal for replacement operations is to use relatively short regexes, since I want you to minimize the number
|
| 49 |
+
of output tokens. For replacements of larger chunks of code, this means you intelligently make use of wildcards for the middle part
|
| 50 |
+
and of characteristic snippets for the before/after parts that uniquely identify the chunk.
|
| 51 |
+
|
| 52 |
+
For small replacements, up to a single line, you follow the following rules:
|
| 53 |
+
|
| 54 |
+
1. If the snippet to be replaced is likely to be unique within the file, you perform the replacement by directly using the escaped version of the
|
| 55 |
+
original.
|
| 56 |
+
2. If the snippet is probably not unique, and you want to replace all occurrences, you use the `allow_multiple_occurrences` flag.
|
| 57 |
+
3. If the snippet is not unique, and you want to replace a specific occurrence, you make use of the code surrounding the snippet
|
| 58 |
+
to extend the regex with content before/after such that the regex will have exactly one match.
|
| 59 |
+
4. You generally assume that a snippet is unique, knowing that the tool will return an error on multiple matches. You only read more file content
|
| 60 |
+
(for crafvarting a more specific regex) if such a failure unexpectedly occurs.
|
| 61 |
+
|
| 62 |
+
Examples:
|
| 63 |
+
|
| 64 |
+
1 Small replacement
|
| 65 |
+
You have read code like
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
...
|
| 69 |
+
x = linear(x)
|
| 70 |
+
x = relu(x)
|
| 71 |
+
return x
|
| 72 |
+
...
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
and you want to replace `x = relu(x)` with `x = gelu(x)`.
|
| 76 |
+
You first try `replace_regex()` with the regex `x = relu\(x\)` and the replacement `x = gelu(x)`.
|
| 77 |
+
If this fails due to multiple matches, you will try `(linear\(x\)\s*)x = relu\(x\)(\s*return)` with the replacement `\1x = gelu(x)\2`.
|
| 78 |
+
|
| 79 |
+
2 Larger replacement
|
| 80 |
+
|
| 81 |
+
You have read code like
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
def my_func():
|
| 85 |
+
...
|
| 86 |
+
# a comment before the snippet
|
| 87 |
+
x = add_fifteen(x)
|
| 88 |
+
# beginning of long section within my_func
|
| 89 |
+
....
|
| 90 |
+
# end of long section
|
| 91 |
+
call_subroutine(z)
|
| 92 |
+
call_second_subroutine(z)
|
| 93 |
+
```
|
| 94 |
+
and you want to replace the code starting with `x = add_fifteen(x)` until (including) `call_subroutine(z)`, but not `call_second_subroutine(z)`.
|
| 95 |
+
Initially, you assume that the the beginning and end of the chunk uniquely determine it within the file.
|
| 96 |
+
Therefore, you perform the replacement by using the regex `x = add_fifteen\(x\)\s*.*?call_subroutine\(z\)`
|
| 97 |
+
and the replacement being the new code you want to insert.
|
| 98 |
+
|
| 99 |
+
If this fails due to multiple matches, you will try to extend the regex with the content before/after the snippet and match groups.
|
| 100 |
+
The matching regex becomes:
|
| 101 |
+
`(before the snippet\s*)x = add_fifteen\(x\)\s*.*?call_subroutine\(z\)`
|
| 102 |
+
and the replacement includes the group as (schematically):
|
| 103 |
+
`\1<new_code>`
|
| 104 |
+
|
| 105 |
+
Generally, I remind you that you rely on the regex tool with providing you the correct feedback, no need for more verification!
|
| 106 |
+
|
| 107 |
+
IMPORTANT: REMEMBER TO USE WILDCARDS WHEN APPROPRIATE! I WILL BE VERY UNHAPPY IF YOU WRITE LONG REGEXES WITHOUT USING WILDCARDS INSTEAD!
|
| 108 |
+
{% endif %}
|
| 109 |
+
excluded_tools:
|
| 110 |
+
- replace_lines
|
| 111 |
+
- insert_at_line
|
| 112 |
+
- delete_lines
|
projects/ui/serena-new/src/serena/resources/config/modes/interactive.yml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: Interactive mode for clarification and step-by-step work
|
| 2 |
+
prompt: |
|
| 3 |
+
You are operating in interactive mode. You should engage with the user throughout the task, asking for clarification
|
| 4 |
+
whenever anything is unclear, insufficiently specified, or ambiguous.
|
| 5 |
+
|
| 6 |
+
Break down complex tasks into smaller steps and explain your thinking at each stage. When you're uncertain about
|
| 7 |
+
a decision, present options to the user and ask for guidance rather than making assumptions.
|
| 8 |
+
|
| 9 |
+
Focus on providing informative results for intermediate steps so the user can follow along with your progress and
|
| 10 |
+
provide feedback as needed.
|
| 11 |
+
excluded_tools: []
|
projects/ui/serena-new/src/serena/resources/config/modes/mode.template.yml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# See Serena's documentation for more details on concept of modes.
|
| 2 |
+
description: Description of the mode, not used in the code.
|
| 3 |
+
prompt: Prompt that will form part of the message sent to the model when activating this mode.
|
| 4 |
+
excluded_tools: []
|
| 5 |
+
|
| 6 |
+
# several tools are excluded by default and have to be explicitly included by the user
|
| 7 |
+
included_optional_tools: []
|
projects/ui/serena-new/src/serena/resources/config/modes/no-onboarding.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: Onboarding was already performed, exclude all onboarding tools
|
| 2 |
+
prompt: |
|
| 3 |
+
You have already performed onboarding, meaning that memories have already been created.
|
| 4 |
+
Read a list of available memories using the `list_memories` tool before proceeding with the task.
|
| 5 |
+
You don't need to read the actual memories, just remember that they exist and that you can read them later if they are relevant for your task.
|
| 6 |
+
excluded_tools:
|
| 7 |
+
- onboarding
|
| 8 |
+
- check_onboarding_performed
|
projects/ui/serena-new/src/serena/resources/config/modes/onboarding.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: Only read-only tools, focused on analysis and planning
|
| 2 |
+
prompt: |
|
| 3 |
+
You are operating in onboarding mode. This is the first time you are seeing the project.
|
| 4 |
+
Your task is to collect relevant information about it and to save memories using the tools provided.
|
| 5 |
+
Call relevant onboarding tools for more instructions on how to do this.
|
| 6 |
+
In this mode, you should not be modifying any existing files.
|
| 7 |
+
If you are also in interactive mode and something about the project is unclear, ask the user for clarification.
|
| 8 |
+
excluded_tools:
|
| 9 |
+
- create_text_file
|
| 10 |
+
- replace_symbol_body
|
| 11 |
+
- insert_after_symbol
|
| 12 |
+
- insert_before_symbol
|
| 13 |
+
- delete_lines
|
| 14 |
+
- replace_lines
|
| 15 |
+
- insert_at_line
|
| 16 |
+
- execute_shell_command
|
projects/ui/serena-new/src/serena/resources/config/modes/one-shot.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: Focus on completely finishing a task without interaction
|
| 2 |
+
prompt: |
|
| 3 |
+
You are operating in one-shot mode. Your goal is to complete the entire task autonomously without further user interaction.
|
| 4 |
+
You should assume auto-approval for all tools and continue working until the task is completely finished.
|
| 5 |
+
|
| 6 |
+
If the task is planning, your final result should be a comprehensive plan. If the task is coding, your final result
|
| 7 |
+
should be working code with all requirements fulfilled. Try to understand what the user asks you to do
|
| 8 |
+
and to assume as little as possible.
|
| 9 |
+
|
| 10 |
+
Only abort the task if absolutely necessary, such as when critical information is missing that cannot be inferred
|
| 11 |
+
from the codebase.
|
| 12 |
+
|
| 13 |
+
It may be that you have not received a task yet. In this case, wait for the user to provide a task, this will be the
|
| 14 |
+
only time you should wait for user interaction.
|
| 15 |
+
excluded_tools: []
|
projects/ui/serena-new/src/serena/resources/config/modes/planning.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
description: Only read-only tools, focused on analysis and planning
|
| 2 |
+
prompt: |
|
| 3 |
+
You are operating in planning mode. Your task is to analyze code but not write any code.
|
| 4 |
+
The user may ask you to assist in creating a comprehensive plan, or to learn something about the codebase -
|
| 5 |
+
either a small aspect of it or about the whole project.
|
| 6 |
+
excluded_tools:
|
| 7 |
+
- create_text_file
|
| 8 |
+
- replace_symbol_body
|
| 9 |
+
- insert_after_symbol
|
| 10 |
+
- insert_before_symbol
|
| 11 |
+
- delete_lines
|
| 12 |
+
- replace_lines
|
| 13 |
+
- insert_at_line
|
| 14 |
+
- execute_shell_command
|
| 15 |
+
- replace_regex
|
projects/ui/serena-new/src/serena/resources/config/prompt_templates/simple_tool_outputs.yml
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Some of Serena's tools are just outputting a fixed text block without doing anything else.
|
| 2 |
+
# Such tools are meant to encourage the agent to think in a certain way, to stay on track
|
| 3 |
+
# and so on. The (templates for) outputs of these tools are contained here.
|
| 4 |
+
prompts:
|
| 5 |
+
onboarding_prompt: |
|
| 6 |
+
You are viewing the project for the first time.
|
| 7 |
+
Your task is to assemble relevant high-level information about the project which
|
| 8 |
+
will be saved to memory files in the following steps.
|
| 9 |
+
The information should be sufficient to understand what the project is about,
|
| 10 |
+
and the most important commands for developing code.
|
| 11 |
+
The project is being developed on the system: {{ system }}.
|
| 12 |
+
|
| 13 |
+
You need to identify at least the following information:
|
| 14 |
+
* the project's purpose
|
| 15 |
+
* the tech stack used
|
| 16 |
+
* the code style and conventions used (including naming, type hints, docstrings, etc.)
|
| 17 |
+
* which commands to run when a task is completed (linting, formatting, testing, etc.)
|
| 18 |
+
* the rough structure of the codebase
|
| 19 |
+
* the commands for testing, formatting, and linting
|
| 20 |
+
* the commands for running the entrypoints of the project
|
| 21 |
+
* the util commands for the system, like `git`, `ls`, `cd`, `grep`, `find`, etc. Keep in mind that the system is {{ system }},
|
| 22 |
+
so the commands might be different than on a regular unix system.
|
| 23 |
+
* whether there are particular guidelines, styles, design patterns, etc. that one should know about
|
| 24 |
+
|
| 25 |
+
This list is not exhaustive, you can add more information if you think it is relevant.
|
| 26 |
+
|
| 27 |
+
For doing that, you will need to acquire information about the project with the corresponding tools.
|
| 28 |
+
Read only the necessary files and directories to avoid loading too much data into memory.
|
| 29 |
+
If you cannot find everything you need from the project itself, you should ask the user for more information.
|
| 30 |
+
|
| 31 |
+
After collecting all the information, you will use the `write_memory` tool (in multiple calls) to save it to various memory files.
|
| 32 |
+
A particularly important memory file will be the `suggested_commands.md` file, which should contain
|
| 33 |
+
a list of commands that the user should know about to develop code in this project.
|
| 34 |
+
Moreover, you should create memory files for the style and conventions and a dedicated memory file for
|
| 35 |
+
what should be done when a task is completed.
|
| 36 |
+
**Important**: after done with the onboarding task, remember to call the `write_memory` to save the collected information!
|
| 37 |
+
|
| 38 |
+
think_about_collected_information: |
|
| 39 |
+
Have you collected all the information you need for solving the current task? If not, can the missing information be acquired by using the available tools,
|
| 40 |
+
in particular the tools related to symbol discovery? Or do you need to ask the user for more information?
|
| 41 |
+
Think about it step by step and give a summary of the missing information and how it could be acquired.
|
| 42 |
+
|
| 43 |
+
think_about_task_adherence: |
|
| 44 |
+
Are you deviating from the task at hand? Do you need any additional information to proceed?
|
| 45 |
+
Have you loaded all relevant memory files to see whether your implementation is fully aligned with the
|
| 46 |
+
code style, conventions, and guidelines of the project? If not, adjust your implementation accordingly
|
| 47 |
+
before modifying any code into the codebase.
|
| 48 |
+
Note that it is better to stop and ask the user for clarification
|
| 49 |
+
than to perform large changes which might not be aligned with the user's intentions.
|
| 50 |
+
If you feel like the conversation is deviating too much from the original task, apologize and suggest to the user
|
| 51 |
+
how to proceed. If the conversation became too long, create a summary of the current progress and suggest to the user
|
| 52 |
+
to start a new conversation based on that summary.
|
| 53 |
+
|
| 54 |
+
think_about_whether_you_are_done: |
|
| 55 |
+
Have you already performed all the steps required by the task? Is it appropriate to run tests and linting, and if so,
|
| 56 |
+
have you done that already? Is it appropriate to adjust non-code files like documentation and config and have you done that already?
|
| 57 |
+
Should new tests be written to cover the changes?
|
| 58 |
+
Note that a task that is just about exploring the codebase does not require running tests or linting.
|
| 59 |
+
Read the corresponding memory files to see what should be done when a task is completed.
|
| 60 |
+
|
| 61 |
+
summarize_changes: |
|
| 62 |
+
Summarize all the changes you have made to the codebase over the course of the conversation.
|
| 63 |
+
Explore the diff if needed (e.g. by using `git diff`) to ensure that you have not missed anything.
|
| 64 |
+
Explain whether and how the changes are covered by tests. Explain how to best use the new code, how to understand it,
|
| 65 |
+
which existing code it affects and interacts with. Are there any dangers (like potential breaking changes or potential new problems)
|
| 66 |
+
that the user should be aware of? Should any new documentation be written or existing documentation updated?
|
| 67 |
+
You can use tools to explore the codebase prior to writing the summary, but don't write any new code in this step until
|
| 68 |
+
the summary is complete.
|
| 69 |
+
|
| 70 |
+
prepare_for_new_conversation: |
|
| 71 |
+
You have not yet completed the current task but we are running out of context.
|
| 72 |
+
{mode_prepare_for_new_conversation}
|
| 73 |
+
Imagine that you are handing over the task to another person who has access to the
|
| 74 |
+
same tools and memory files as you do, but has not been part of the conversation so far.
|
| 75 |
+
Write a summary that can be used in the next conversation to a memory file using the `write_memory` tool.
|
projects/ui/serena-new/src/serena/resources/config/prompt_templates/system_prompt.yml
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The system prompt template. Note that many clients will not allow configuration of the actual system prompt,
|
| 2 |
+
# in which case this prompt will be given as a regular message on the call of a simple tool which the agent
|
| 3 |
+
# is encouraged (via the tool description) to call at the beginning of the conversation.
|
| 4 |
+
prompts:
|
| 5 |
+
system_prompt: |
|
| 6 |
+
You are a professional coding agent concerned with one particular codebase. You have
|
| 7 |
+
access to semantic coding tools on which you rely heavily for all your work, as well as collection of memory
|
| 8 |
+
files containing general information about the codebase. You operate in a resource-efficient and intelligent manner, always
|
| 9 |
+
keeping in mind to not read or generate content that is not needed for the task at hand.
|
| 10 |
+
|
| 11 |
+
When reading code in order to answer a user question or task, you should try reading only the necessary code.
|
| 12 |
+
Some tasks may require you to understand the architecture of large parts of the codebase, while for others,
|
| 13 |
+
it may be enough to read a small set of symbols or a single file.
|
| 14 |
+
Generally, you should avoid reading entire files unless it is absolutely necessary, instead relying on
|
| 15 |
+
intelligent step-by-step acquisition of information. {% if 'ToolMarkerSymbolicRead' in available_markers %}However, if you already read a file, it does not make
|
| 16 |
+
sense to further analyse it with the symbolic tools (except for the `find_referencing_symbols` tool),
|
| 17 |
+
as you already have the information.{% endif %}
|
| 18 |
+
|
| 19 |
+
I WILL BE SERIOUSLY UPSET IF YOU READ ENTIRE FILES WITHOUT NEED!
|
| 20 |
+
{% if 'ToolMarkerSymbolicRead' in available_markers %}
|
| 21 |
+
CONSIDER INSTEAD USING THE OVERVIEW TOOL AND SYMBOLIC TOOLS TO READ ONLY THE NECESSARY CODE FIRST!
|
| 22 |
+
I WILL BE EVEN MORE UPSET IF AFTER HAVING READ AN ENTIRE FILE YOU KEEP READING THE SAME CONTENT WITH THE SYMBOLIC TOOLS!
|
| 23 |
+
THE PURPOSE OF THE SYMBOLIC TOOLS IS TO HAVE TO READ LESS CODE, NOT READ THE SAME CONTENT MULTIPLE TIMES!
|
| 24 |
+
{% endif %}
|
| 25 |
+
|
| 26 |
+
You can achieve the intelligent reading of code by using the symbolic tools for getting an overview of symbols and
|
| 27 |
+
the relations between them, and then only reading the bodies of symbols that are necessary to answer the question
|
| 28 |
+
or complete the task.
|
| 29 |
+
You can use the standard tools like list_dir, find_file and search_for_pattern if you need to.
|
| 30 |
+
When tools allow it, you pass the `relative_path` parameter to restrict the search to a specific file or directory.
|
| 31 |
+
For some tools, `relative_path` can only be a file path, so make sure to properly read the tool descriptions.
|
| 32 |
+
{% if 'search_for_pattern' in available_tools %}
|
| 33 |
+
If you are unsure about a symbol's name or location{% if 'find_symbol' in available_tools %} (to the extent that substring_matching for the symbol name is not enough){% endif %}, you can use the `search_for_pattern` tool, which allows fast
|
| 34 |
+
and flexible search for patterns in the codebase.{% if 'ToolMarkerSymbolicRead' in available_markers %}This way you can first find candidates for symbols or files,
|
| 35 |
+
and then proceed with the symbolic tools.{% endif %}
|
| 36 |
+
{% endif %}
|
| 37 |
+
|
| 38 |
+
{% if 'ToolMarkerSymbolicRead' in available_markers %}
|
| 39 |
+
Symbols are identified by their `name_path and `relative_path`, see the description of the `find_symbol` tool for more details
|
| 40 |
+
on how the `name_path` matches symbols.
|
| 41 |
+
You can get information about available symbols by using the `get_symbols_overview` tool for finding top-level symbols in a file,
|
| 42 |
+
or by using `find_symbol` if you already know the symbol's name path. You generally try to read as little code as possible
|
| 43 |
+
while still solving your task, meaning you only read the bodies when you need to, and after you have found the symbol you want to edit.
|
| 44 |
+
For example, if you are working with python code and already know that you need to read the body of the constructor of the class Foo, you can directly
|
| 45 |
+
use `find_symbol` with the name path `Foo/__init__` and `include_body=True`. If you don't know yet which methods in `Foo` you need to read or edit,
|
| 46 |
+
you can use `find_symbol` with the name path `Foo`, `include_body=False` and `depth=1` to get all (top-level) methods of `Foo` before proceeding
|
| 47 |
+
to read the desired methods with `include_body=True`
|
| 48 |
+
You can understand relationships between symbols by using the `find_referencing_symbols` tool.
|
| 49 |
+
{% endif %}
|
| 50 |
+
|
| 51 |
+
{% if 'read_memory' in available_tools %}
|
| 52 |
+
You generally have access to memories and it may be useful for you to read them, but also only if they help you
|
| 53 |
+
to answer the question or complete the task. You can infer which memories are relevant to the current task by reading
|
| 54 |
+
the memory names and descriptions.
|
| 55 |
+
{% endif %}
|
| 56 |
+
|
| 57 |
+
The context and modes of operation are described below. From them you can infer how to interact with your user
|
| 58 |
+
and which tasks and kinds of interactions are expected of you.
|
| 59 |
+
|
| 60 |
+
Context description:
|
| 61 |
+
{{ context_system_prompt }}
|
| 62 |
+
|
| 63 |
+
Modes descriptions:
|
| 64 |
+
{% for prompt in mode_system_prompts %}
|
| 65 |
+
- {{ prompt }}
|
| 66 |
+
{% endfor %}
|
projects/ui/serena-new/src/solidlsp/language_servers/bash_language_server.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Bash specific instantiation of the LanguageServer class using bash-language-server.
|
| 3 |
+
Contains various configurations and settings specific to Bash scripting.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import shutil
|
| 10 |
+
import threading
|
| 11 |
+
|
| 12 |
+
from solidlsp import ls_types
|
| 13 |
+
from solidlsp.language_servers.common import RuntimeDependency, RuntimeDependencyCollection
|
| 14 |
+
from solidlsp.ls import SolidLanguageServer
|
| 15 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 16 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 17 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 18 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 19 |
+
from solidlsp.settings import SolidLSPSettings
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class BashLanguageServer(SolidLanguageServer):
|
| 23 |
+
"""
|
| 24 |
+
Provides Bash specific instantiation of the LanguageServer class using bash-language-server.
|
| 25 |
+
Contains various configurations and settings specific to Bash scripting.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def __init__(
|
| 29 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 30 |
+
):
|
| 31 |
+
"""
|
| 32 |
+
Creates a BashLanguageServer instance. This class is not meant to be instantiated directly.
|
| 33 |
+
Use LanguageServer.create() instead.
|
| 34 |
+
"""
|
| 35 |
+
bash_lsp_executable_path = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 36 |
+
super().__init__(
|
| 37 |
+
config,
|
| 38 |
+
logger,
|
| 39 |
+
repository_root_path,
|
| 40 |
+
ProcessLaunchInfo(cmd=bash_lsp_executable_path, cwd=repository_root_path),
|
| 41 |
+
"bash",
|
| 42 |
+
solidlsp_settings,
|
| 43 |
+
)
|
| 44 |
+
self.server_ready = threading.Event()
|
| 45 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 46 |
+
|
| 47 |
+
@classmethod
|
| 48 |
+
def _setup_runtime_dependencies(
|
| 49 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 50 |
+
) -> str:
|
| 51 |
+
"""
|
| 52 |
+
Setup runtime dependencies for Bash Language Server and return the command to start the server.
|
| 53 |
+
"""
|
| 54 |
+
# Verify both node and npm are installed
|
| 55 |
+
is_node_installed = shutil.which("node") is not None
|
| 56 |
+
assert is_node_installed, "node is not installed or isn't in PATH. Please install NodeJS and try again."
|
| 57 |
+
is_npm_installed = shutil.which("npm") is not None
|
| 58 |
+
assert is_npm_installed, "npm is not installed or isn't in PATH. Please install npm and try again."
|
| 59 |
+
|
| 60 |
+
deps = RuntimeDependencyCollection(
|
| 61 |
+
[
|
| 62 |
+
RuntimeDependency(
|
| 63 |
+
id="bash-language-server",
|
| 64 |
+
description="bash-language-server package",
|
| 65 |
+
command="npm install --prefix ./ bash-language-server@5.6.0",
|
| 66 |
+
platform_id="any",
|
| 67 |
+
),
|
| 68 |
+
]
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Install bash-language-server if not already installed
|
| 72 |
+
bash_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "bash-lsp")
|
| 73 |
+
bash_executable_path = os.path.join(bash_ls_dir, "node_modules", ".bin", "bash-language-server")
|
| 74 |
+
|
| 75 |
+
# Handle Windows executable extension
|
| 76 |
+
if os.name == "nt":
|
| 77 |
+
bash_executable_path += ".cmd"
|
| 78 |
+
|
| 79 |
+
if not os.path.exists(bash_executable_path):
|
| 80 |
+
logger.log(f"Bash Language Server executable not found at {bash_executable_path}. Installing...", logging.INFO)
|
| 81 |
+
deps.install(logger, bash_ls_dir)
|
| 82 |
+
logger.log("Bash language server dependencies installed successfully", logging.INFO)
|
| 83 |
+
|
| 84 |
+
if not os.path.exists(bash_executable_path):
|
| 85 |
+
raise FileNotFoundError(
|
| 86 |
+
f"bash-language-server executable not found at {bash_executable_path}, something went wrong with the installation."
|
| 87 |
+
)
|
| 88 |
+
return f"{bash_executable_path} start"
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 92 |
+
"""
|
| 93 |
+
Returns the initialize params for the Bash Language Server.
|
| 94 |
+
"""
|
| 95 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 96 |
+
initialize_params = {
|
| 97 |
+
"locale": "en",
|
| 98 |
+
"capabilities": {
|
| 99 |
+
"textDocument": {
|
| 100 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 101 |
+
"completion": {"dynamicRegistration": True, "completionItem": {"snippetSupport": True}},
|
| 102 |
+
"definition": {"dynamicRegistration": True},
|
| 103 |
+
"references": {"dynamicRegistration": True},
|
| 104 |
+
"documentSymbol": {
|
| 105 |
+
"dynamicRegistration": True,
|
| 106 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 107 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 108 |
+
},
|
| 109 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 110 |
+
"signatureHelp": {"dynamicRegistration": True},
|
| 111 |
+
"codeAction": {"dynamicRegistration": True},
|
| 112 |
+
},
|
| 113 |
+
"workspace": {
|
| 114 |
+
"workspaceFolders": True,
|
| 115 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 116 |
+
"symbol": {"dynamicRegistration": True},
|
| 117 |
+
},
|
| 118 |
+
},
|
| 119 |
+
"processId": os.getpid(),
|
| 120 |
+
"rootPath": repository_absolute_path,
|
| 121 |
+
"rootUri": root_uri,
|
| 122 |
+
"workspaceFolders": [
|
| 123 |
+
{
|
| 124 |
+
"uri": root_uri,
|
| 125 |
+
"name": os.path.basename(repository_absolute_path),
|
| 126 |
+
}
|
| 127 |
+
],
|
| 128 |
+
}
|
| 129 |
+
return initialize_params
|
| 130 |
+
|
| 131 |
+
def _start_server(self):
|
| 132 |
+
"""
|
| 133 |
+
Starts the Bash Language Server, waits for the server to be ready and yields the LanguageServer instance.
|
| 134 |
+
"""
|
| 135 |
+
|
| 136 |
+
def register_capability_handler(params):
|
| 137 |
+
assert "registrations" in params
|
| 138 |
+
for registration in params["registrations"]:
|
| 139 |
+
if registration["method"] == "workspace/executeCommand":
|
| 140 |
+
self.initialize_searcher_command_available.set()
|
| 141 |
+
return
|
| 142 |
+
|
| 143 |
+
def execute_client_command_handler(params):
|
| 144 |
+
return []
|
| 145 |
+
|
| 146 |
+
def do_nothing(params):
|
| 147 |
+
return
|
| 148 |
+
|
| 149 |
+
def window_log_message(msg):
|
| 150 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 151 |
+
# Check for bash-language-server ready signals
|
| 152 |
+
message_text = msg.get("message", "")
|
| 153 |
+
if "Analyzing" in message_text or "analysis complete" in message_text.lower():
|
| 154 |
+
self.logger.log("Bash language server analysis signals detected", logging.INFO)
|
| 155 |
+
self.server_ready.set()
|
| 156 |
+
self.completions_available.set()
|
| 157 |
+
|
| 158 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 159 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 160 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 161 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 162 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 163 |
+
|
| 164 |
+
self.logger.log("Starting Bash server process", logging.INFO)
|
| 165 |
+
self.server.start()
|
| 166 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 167 |
+
|
| 168 |
+
self.logger.log(
|
| 169 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 170 |
+
logging.INFO,
|
| 171 |
+
)
|
| 172 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 173 |
+
self.logger.log(f"Received initialize response from bash server: {init_response}", logging.DEBUG)
|
| 174 |
+
|
| 175 |
+
# Enhanced capability checks for bash-language-server 5.6.0
|
| 176 |
+
assert init_response["capabilities"]["textDocumentSync"] in [1, 2] # Full or Incremental
|
| 177 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 178 |
+
|
| 179 |
+
# Verify document symbol support is available
|
| 180 |
+
if "documentSymbolProvider" in init_response["capabilities"]:
|
| 181 |
+
self.logger.log("Bash server supports document symbols", logging.INFO)
|
| 182 |
+
else:
|
| 183 |
+
self.logger.log("Warning: Bash server does not report document symbol support", logging.WARNING)
|
| 184 |
+
|
| 185 |
+
self.server.notify.initialized({})
|
| 186 |
+
|
| 187 |
+
# Wait for server readiness with timeout
|
| 188 |
+
self.logger.log("Waiting for Bash language server to be ready...", logging.INFO)
|
| 189 |
+
if not self.server_ready.wait(timeout=3.0):
|
| 190 |
+
# Fallback: assume server is ready after timeout
|
| 191 |
+
self.logger.log("Timeout waiting for bash server ready signal, proceeding anyway", logging.WARNING)
|
| 192 |
+
self.server_ready.set()
|
| 193 |
+
self.completions_available.set()
|
| 194 |
+
else:
|
| 195 |
+
self.logger.log("Bash server initialization complete", logging.INFO)
|
| 196 |
+
|
| 197 |
+
def request_document_symbols(
|
| 198 |
+
self, relative_file_path: str, include_body: bool = False
|
| 199 |
+
) -> tuple[list[ls_types.UnifiedSymbolInformation], list[ls_types.UnifiedSymbolInformation]]:
|
| 200 |
+
"""
|
| 201 |
+
Request document symbols from bash-language-server via LSP.
|
| 202 |
+
|
| 203 |
+
Uses the standard LSP documentSymbol request which provides reliable function detection
|
| 204 |
+
for all bash function syntaxes including:
|
| 205 |
+
- function name() { ... } (with function keyword)
|
| 206 |
+
- name() { ... } (traditional syntax)
|
| 207 |
+
- Functions with various indentation levels
|
| 208 |
+
- Functions with comments before/after/inside
|
| 209 |
+
|
| 210 |
+
Args:
|
| 211 |
+
relative_file_path: Path to the bash file relative to repository root
|
| 212 |
+
include_body: Whether to include function bodies in symbol information
|
| 213 |
+
|
| 214 |
+
Returns:
|
| 215 |
+
Tuple of (all_symbols, root_symbols) detected by the LSP server
|
| 216 |
+
|
| 217 |
+
"""
|
| 218 |
+
self.logger.log(f"Requesting document symbols via LSP for {relative_file_path}", logging.DEBUG)
|
| 219 |
+
|
| 220 |
+
# Use the standard LSP approach - bash-language-server handles all function syntaxes correctly
|
| 221 |
+
all_symbols, root_symbols = super().request_document_symbols(relative_file_path, include_body)
|
| 222 |
+
|
| 223 |
+
# Log detection results for debugging
|
| 224 |
+
functions = [s for s in all_symbols if s.get("kind") == 12]
|
| 225 |
+
self.logger.log(
|
| 226 |
+
f"LSP function detection for {relative_file_path}: Found {len(functions)} functions",
|
| 227 |
+
logging.INFO,
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
return all_symbols, root_symbols
|
projects/ui/serena-new/src/solidlsp/language_servers/clangd_language_server.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import threading
|
| 9 |
+
|
| 10 |
+
from solidlsp.ls import SolidLanguageServer
|
| 11 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 12 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 13 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 14 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 15 |
+
from solidlsp.settings import SolidLSPSettings
|
| 16 |
+
|
| 17 |
+
from .common import RuntimeDependency, RuntimeDependencyCollection
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class ClangdLanguageServer(SolidLanguageServer):
|
| 21 |
+
"""
|
| 22 |
+
Provides C/C++ specific instantiation of the LanguageServer class. Contains various configurations and settings specific to C/C++.
|
| 23 |
+
As the project gets bigger in size, building index will take time. Try running clangd multiple times to ensure index is built properly.
|
| 24 |
+
Also make sure compile_commands.json is created at root of the source directory. Check clangd test case for example.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
def __init__(
|
| 28 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 29 |
+
):
|
| 30 |
+
"""
|
| 31 |
+
Creates a ClangdLanguageServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 32 |
+
"""
|
| 33 |
+
clangd_executable_path = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 34 |
+
super().__init__(
|
| 35 |
+
config,
|
| 36 |
+
logger,
|
| 37 |
+
repository_root_path,
|
| 38 |
+
ProcessLaunchInfo(cmd=clangd_executable_path, cwd=repository_root_path),
|
| 39 |
+
"cpp",
|
| 40 |
+
solidlsp_settings,
|
| 41 |
+
)
|
| 42 |
+
self.server_ready = threading.Event()
|
| 43 |
+
self.service_ready_event = threading.Event()
|
| 44 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 45 |
+
self.resolve_main_method_available = threading.Event()
|
| 46 |
+
|
| 47 |
+
@classmethod
|
| 48 |
+
def _setup_runtime_dependencies(
|
| 49 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 50 |
+
) -> str:
|
| 51 |
+
"""
|
| 52 |
+
Setup runtime dependencies for ClangdLanguageServer and return the command to start the server.
|
| 53 |
+
"""
|
| 54 |
+
deps = RuntimeDependencyCollection(
|
| 55 |
+
[
|
| 56 |
+
RuntimeDependency(
|
| 57 |
+
id="Clangd",
|
| 58 |
+
description="Clangd for Linux (x64)",
|
| 59 |
+
url="https://github.com/clangd/clangd/releases/download/19.1.2/clangd-linux-19.1.2.zip",
|
| 60 |
+
platform_id="linux-x64",
|
| 61 |
+
archive_type="zip",
|
| 62 |
+
binary_name="clangd_19.1.2/bin/clangd",
|
| 63 |
+
),
|
| 64 |
+
RuntimeDependency(
|
| 65 |
+
id="Clangd",
|
| 66 |
+
description="Clangd for Windows (x64)",
|
| 67 |
+
url="https://github.com/clangd/clangd/releases/download/19.1.2/clangd-windows-19.1.2.zip",
|
| 68 |
+
platform_id="win-x64",
|
| 69 |
+
archive_type="zip",
|
| 70 |
+
binary_name="clangd_19.1.2/bin/clangd.exe",
|
| 71 |
+
),
|
| 72 |
+
RuntimeDependency(
|
| 73 |
+
id="Clangd",
|
| 74 |
+
description="Clangd for macOS (x64)",
|
| 75 |
+
url="https://github.com/clangd/clangd/releases/download/19.1.2/clangd-mac-19.1.2.zip",
|
| 76 |
+
platform_id="osx-x64",
|
| 77 |
+
archive_type="zip",
|
| 78 |
+
binary_name="clangd_19.1.2/bin/clangd",
|
| 79 |
+
),
|
| 80 |
+
RuntimeDependency(
|
| 81 |
+
id="Clangd",
|
| 82 |
+
description="Clangd for macOS (Arm64)",
|
| 83 |
+
url="https://github.com/clangd/clangd/releases/download/19.1.2/clangd-mac-19.1.2.zip",
|
| 84 |
+
platform_id="osx-arm64",
|
| 85 |
+
archive_type="zip",
|
| 86 |
+
binary_name="clangd_19.1.2/bin/clangd",
|
| 87 |
+
),
|
| 88 |
+
]
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
clangd_ls_dir = os.path.join(cls.ls_resources_dir(solidlsp_settings), "clangd")
|
| 92 |
+
dep = deps.single_for_current_platform()
|
| 93 |
+
clangd_executable_path = deps.binary_path(clangd_ls_dir)
|
| 94 |
+
if not os.path.exists(clangd_executable_path):
|
| 95 |
+
logger.log(
|
| 96 |
+
f"Clangd executable not found at {clangd_executable_path}. Downloading from {dep.url}",
|
| 97 |
+
logging.INFO,
|
| 98 |
+
)
|
| 99 |
+
deps.install(logger, clangd_ls_dir)
|
| 100 |
+
if not os.path.exists(clangd_executable_path):
|
| 101 |
+
raise FileNotFoundError(
|
| 102 |
+
f"Clangd executable not found at {clangd_executable_path}.\n"
|
| 103 |
+
"Make sure you have installed clangd. See https://clangd.llvm.org/installation"
|
| 104 |
+
)
|
| 105 |
+
os.chmod(clangd_executable_path, 0o755)
|
| 106 |
+
|
| 107 |
+
return clangd_executable_path
|
| 108 |
+
|
| 109 |
+
@staticmethod
|
| 110 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 111 |
+
"""
|
| 112 |
+
Returns the initialize params for the clangd Language Server.
|
| 113 |
+
"""
|
| 114 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 115 |
+
initialize_params = {
|
| 116 |
+
"locale": "en",
|
| 117 |
+
"capabilities": {
|
| 118 |
+
"textDocument": {
|
| 119 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 120 |
+
"completion": {"dynamicRegistration": True, "completionItem": {"snippetSupport": True}},
|
| 121 |
+
"definition": {"dynamicRegistration": True},
|
| 122 |
+
},
|
| 123 |
+
"workspace": {"workspaceFolders": True, "didChangeConfiguration": {"dynamicRegistration": True}},
|
| 124 |
+
},
|
| 125 |
+
"processId": os.getpid(),
|
| 126 |
+
"rootPath": repository_absolute_path,
|
| 127 |
+
"rootUri": root_uri,
|
| 128 |
+
"workspaceFolders": [
|
| 129 |
+
{
|
| 130 |
+
"uri": root_uri,
|
| 131 |
+
"name": "$name",
|
| 132 |
+
}
|
| 133 |
+
],
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
return initialize_params
|
| 137 |
+
|
| 138 |
+
def _start_server(self):
|
| 139 |
+
"""
|
| 140 |
+
Starts the Clangd Language Server, waits for the server to be ready and yields the LanguageServer instance.
|
| 141 |
+
|
| 142 |
+
Usage:
|
| 143 |
+
```
|
| 144 |
+
async with lsp.start_server():
|
| 145 |
+
# LanguageServer has been initialized and ready to serve requests
|
| 146 |
+
await lsp.request_definition(...)
|
| 147 |
+
await lsp.request_references(...)
|
| 148 |
+
# Shutdown the LanguageServer on exit from scope
|
| 149 |
+
# LanguageServer has been shutdown
|
| 150 |
+
"""
|
| 151 |
+
|
| 152 |
+
def register_capability_handler(params):
|
| 153 |
+
assert "registrations" in params
|
| 154 |
+
for registration in params["registrations"]:
|
| 155 |
+
if registration["method"] == "workspace/executeCommand":
|
| 156 |
+
self.initialize_searcher_command_available.set()
|
| 157 |
+
self.resolve_main_method_available.set()
|
| 158 |
+
return
|
| 159 |
+
|
| 160 |
+
def lang_status_handler(params):
|
| 161 |
+
# TODO: Should we wait for
|
| 162 |
+
# server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}
|
| 163 |
+
# Before proceeding?
|
| 164 |
+
if params["type"] == "ServiceReady" and params["message"] == "ServiceReady":
|
| 165 |
+
self.service_ready_event.set()
|
| 166 |
+
|
| 167 |
+
def execute_client_command_handler(params):
|
| 168 |
+
return []
|
| 169 |
+
|
| 170 |
+
def do_nothing(params):
|
| 171 |
+
return
|
| 172 |
+
|
| 173 |
+
def check_experimental_status(params):
|
| 174 |
+
if params["quiescent"] == True:
|
| 175 |
+
self.server_ready.set()
|
| 176 |
+
|
| 177 |
+
def window_log_message(msg):
|
| 178 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 179 |
+
|
| 180 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 181 |
+
self.server.on_notification("language/status", lang_status_handler)
|
| 182 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 183 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 184 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 185 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 186 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 187 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 188 |
+
|
| 189 |
+
self.logger.log("Starting Clangd server process", logging.INFO)
|
| 190 |
+
self.server.start()
|
| 191 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 192 |
+
|
| 193 |
+
self.logger.log(
|
| 194 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 195 |
+
logging.INFO,
|
| 196 |
+
)
|
| 197 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 198 |
+
assert init_response["capabilities"]["textDocumentSync"]["change"] == 2
|
| 199 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 200 |
+
assert init_response["capabilities"]["completionProvider"] == {
|
| 201 |
+
"triggerCharacters": [".", "<", ">", ":", '"', "/", "*"],
|
| 202 |
+
"resolveProvider": False,
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
self.server.notify.initialized({})
|
| 206 |
+
|
| 207 |
+
self.completions_available.set()
|
| 208 |
+
# set ready flag
|
| 209 |
+
self.server_ready.set()
|
| 210 |
+
self.server_ready.wait()
|
projects/ui/serena-new/src/solidlsp/language_servers/clojure_lsp.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Provides Clojure specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Clojure.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import shutil
|
| 9 |
+
import subprocess
|
| 10 |
+
import threading
|
| 11 |
+
|
| 12 |
+
from solidlsp.ls import SolidLanguageServer
|
| 13 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 14 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 15 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 16 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 17 |
+
from solidlsp.settings import SolidLSPSettings
|
| 18 |
+
|
| 19 |
+
from .common import RuntimeDependency, RuntimeDependencyCollection
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def run_command(cmd: list, capture_output: bool = True) -> subprocess.CompletedProcess:
|
| 23 |
+
return subprocess.run(
|
| 24 |
+
cmd, stdout=subprocess.PIPE if capture_output else None, stderr=subprocess.STDOUT if capture_output else None, text=True, check=True
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def verify_clojure_cli():
|
| 29 |
+
install_msg = "Please install the official Clojure CLI from:\n https://clojure.org/guides/getting_started"
|
| 30 |
+
if shutil.which("clojure") is None:
|
| 31 |
+
raise FileNotFoundError("`clojure` not found.\n" + install_msg)
|
| 32 |
+
|
| 33 |
+
help_proc = run_command(["clojure", "--help"])
|
| 34 |
+
if "-Aaliases" not in help_proc.stdout:
|
| 35 |
+
raise RuntimeError("Detected a Clojure executable, but it does not support '-Aaliases'.\n" + install_msg)
|
| 36 |
+
|
| 37 |
+
spath_proc = run_command(["clojure", "-Spath"], capture_output=False)
|
| 38 |
+
if spath_proc.returncode != 0:
|
| 39 |
+
raise RuntimeError("`clojure -Spath` failed; please upgrade to Clojure CLI ≥ 1.10.")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class ClojureLSP(SolidLanguageServer):
|
| 43 |
+
"""
|
| 44 |
+
Provides a clojure-lsp specific instantiation of the LanguageServer class. Contains various configurations and settings specific to clojure.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
clojure_lsp_releases = "https://github.com/clojure-lsp/clojure-lsp/releases/latest/download"
|
| 48 |
+
runtime_dependencies = RuntimeDependencyCollection(
|
| 49 |
+
[
|
| 50 |
+
RuntimeDependency(
|
| 51 |
+
id="clojure-lsp",
|
| 52 |
+
url=f"{clojure_lsp_releases}/clojure-lsp-native-macos-aarch64.zip",
|
| 53 |
+
platform_id="osx-arm64",
|
| 54 |
+
archive_type="zip",
|
| 55 |
+
binary_name="clojure-lsp",
|
| 56 |
+
),
|
| 57 |
+
RuntimeDependency(
|
| 58 |
+
id="clojure-lsp",
|
| 59 |
+
url=f"{clojure_lsp_releases}/clojure-lsp-native-macos-amd64.zip",
|
| 60 |
+
platform_id="osx-x64",
|
| 61 |
+
archive_type="zip",
|
| 62 |
+
binary_name="clojure-lsp",
|
| 63 |
+
),
|
| 64 |
+
RuntimeDependency(
|
| 65 |
+
id="clojure-lsp",
|
| 66 |
+
url=f"{clojure_lsp_releases}/clojure-lsp-native-linux-aarch64.zip",
|
| 67 |
+
platform_id="linux-arm64",
|
| 68 |
+
archive_type="zip",
|
| 69 |
+
binary_name="clojure-lsp",
|
| 70 |
+
),
|
| 71 |
+
RuntimeDependency(
|
| 72 |
+
id="clojure-lsp",
|
| 73 |
+
url=f"{clojure_lsp_releases}/clojure-lsp-native-linux-amd64.zip",
|
| 74 |
+
platform_id="linux-x64",
|
| 75 |
+
archive_type="zip",
|
| 76 |
+
binary_name="clojure-lsp",
|
| 77 |
+
),
|
| 78 |
+
RuntimeDependency(
|
| 79 |
+
id="clojure-lsp",
|
| 80 |
+
url=f"{clojure_lsp_releases}/clojure-lsp-native-windows-amd64.zip",
|
| 81 |
+
platform_id="win-x64",
|
| 82 |
+
archive_type="zip",
|
| 83 |
+
binary_name="clojure-lsp.exe",
|
| 84 |
+
),
|
| 85 |
+
]
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
def __init__(
|
| 89 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 90 |
+
):
|
| 91 |
+
"""
|
| 92 |
+
Creates a ClojureLSP instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 93 |
+
"""
|
| 94 |
+
clojure_lsp_executable_path = self._setup_runtime_dependencies(logger, config, solidlsp_settings)
|
| 95 |
+
super().__init__(
|
| 96 |
+
config,
|
| 97 |
+
logger,
|
| 98 |
+
repository_root_path,
|
| 99 |
+
ProcessLaunchInfo(cmd=clojure_lsp_executable_path, cwd=repository_root_path),
|
| 100 |
+
"clojure",
|
| 101 |
+
solidlsp_settings,
|
| 102 |
+
)
|
| 103 |
+
self.server_ready = threading.Event()
|
| 104 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 105 |
+
self.resolve_main_method_available = threading.Event()
|
| 106 |
+
self.service_ready_event = threading.Event()
|
| 107 |
+
|
| 108 |
+
@classmethod
|
| 109 |
+
def _setup_runtime_dependencies(
|
| 110 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 111 |
+
) -> str:
|
| 112 |
+
"""Setup runtime dependencies for clojure-lsp and return the command to start the server."""
|
| 113 |
+
verify_clojure_cli()
|
| 114 |
+
deps = ClojureLSP.runtime_dependencies
|
| 115 |
+
dependency = deps.single_for_current_platform()
|
| 116 |
+
|
| 117 |
+
clojurelsp_ls_dir = cls.ls_resources_dir(solidlsp_settings)
|
| 118 |
+
clojurelsp_executable_path = deps.binary_path(clojurelsp_ls_dir)
|
| 119 |
+
if not os.path.exists(clojurelsp_executable_path):
|
| 120 |
+
logger.log(
|
| 121 |
+
f"Downloading and extracting clojure-lsp from {dependency.url} to {clojurelsp_ls_dir}",
|
| 122 |
+
logging.INFO,
|
| 123 |
+
)
|
| 124 |
+
deps.install(logger, clojurelsp_ls_dir)
|
| 125 |
+
if not os.path.exists(clojurelsp_executable_path):
|
| 126 |
+
raise FileNotFoundError(f"Download failed? Could not find clojure-lsp executable at {clojurelsp_executable_path}")
|
| 127 |
+
os.chmod(clojurelsp_executable_path, 0o755)
|
| 128 |
+
return clojurelsp_executable_path
|
| 129 |
+
|
| 130 |
+
@staticmethod
|
| 131 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 132 |
+
"""Returns the init params for clojure-lsp."""
|
| 133 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 134 |
+
return { # type: ignore
|
| 135 |
+
"processId": os.getpid(),
|
| 136 |
+
"rootPath": repository_absolute_path,
|
| 137 |
+
"rootUri": root_uri,
|
| 138 |
+
"capabilities": {
|
| 139 |
+
"workspace": {
|
| 140 |
+
"applyEdit": True,
|
| 141 |
+
"workspaceEdit": {"documentChanges": True},
|
| 142 |
+
"symbol": {"symbolKind": {"valueSet": list(range(1, 27))}},
|
| 143 |
+
"workspaceFolders": True,
|
| 144 |
+
},
|
| 145 |
+
"textDocument": {
|
| 146 |
+
"synchronization": {"didSave": True},
|
| 147 |
+
"publishDiagnostics": {"relatedInformation": True, "tagSupport": {"valueSet": [1, 2]}},
|
| 148 |
+
"definition": {"linkSupport": True},
|
| 149 |
+
"references": {},
|
| 150 |
+
"hover": {"contentFormat": ["markdown", "plaintext"]},
|
| 151 |
+
"documentSymbol": {
|
| 152 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 153 |
+
"symbolKind": {"valueSet": list(range(1, 27))}, #
|
| 154 |
+
},
|
| 155 |
+
},
|
| 156 |
+
"general": {"positionEncodings": ["utf-16"]},
|
| 157 |
+
},
|
| 158 |
+
"initializationOptions": {"dependency-scheme": "jar", "text-document-sync-kind": "incremental"},
|
| 159 |
+
"trace": "off",
|
| 160 |
+
"workspaceFolders": [{"uri": root_uri, "name": os.path.basename(repository_absolute_path)}],
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
def _start_server(self):
|
| 164 |
+
def register_capability_handler(params):
|
| 165 |
+
assert "registrations" in params
|
| 166 |
+
for registration in params["registrations"]:
|
| 167 |
+
if registration["method"] == "workspace/executeCommand":
|
| 168 |
+
self.initialize_searcher_command_available.set()
|
| 169 |
+
self.resolve_main_method_available.set()
|
| 170 |
+
return
|
| 171 |
+
|
| 172 |
+
def lang_status_handler(params):
|
| 173 |
+
# TODO: Should we wait for
|
| 174 |
+
# server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}
|
| 175 |
+
# Before proceeding?
|
| 176 |
+
if params["type"] == "ServiceReady" and params["message"] == "ServiceReady":
|
| 177 |
+
self.service_ready_event.set()
|
| 178 |
+
|
| 179 |
+
def execute_client_command_handler(params):
|
| 180 |
+
return []
|
| 181 |
+
|
| 182 |
+
def do_nothing(params):
|
| 183 |
+
return
|
| 184 |
+
|
| 185 |
+
def check_experimental_status(params):
|
| 186 |
+
if params["quiescent"] == True:
|
| 187 |
+
self.server_ready.set()
|
| 188 |
+
|
| 189 |
+
def window_log_message(msg):
|
| 190 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 191 |
+
|
| 192 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 193 |
+
self.server.on_notification("language/status", lang_status_handler)
|
| 194 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 195 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 196 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 197 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 198 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 199 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 200 |
+
|
| 201 |
+
self.logger.log("Starting clojure-lsp server process", logging.INFO)
|
| 202 |
+
self.server.start()
|
| 203 |
+
|
| 204 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 205 |
+
|
| 206 |
+
self.logger.log(
|
| 207 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 208 |
+
logging.INFO,
|
| 209 |
+
)
|
| 210 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 211 |
+
assert init_response["capabilities"]["textDocumentSync"]["change"] == 2
|
| 212 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 213 |
+
# Clojure-lsp completion provider capabilities are more flexible than other servers'
|
| 214 |
+
completion_provider = init_response["capabilities"]["completionProvider"]
|
| 215 |
+
assert completion_provider["resolveProvider"] == True
|
| 216 |
+
assert "triggerCharacters" in completion_provider
|
| 217 |
+
self.server.notify.initialized({})
|
| 218 |
+
# after initialize, Clojure-lsp is ready to serve
|
| 219 |
+
self.server_ready.set()
|
| 220 |
+
self.completions_available.set()
|
projects/ui/serena-new/src/solidlsp/language_servers/common.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import platform
|
| 6 |
+
import subprocess
|
| 7 |
+
from collections.abc import Sequence
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
|
| 10 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 11 |
+
from solidlsp.ls_utils import FileUtils, PlatformUtils
|
| 12 |
+
from solidlsp.util.subprocess_util import subprocess_kwargs
|
| 13 |
+
|
| 14 |
+
log = logging.getLogger(__name__)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@dataclass(kw_only=True)
|
| 18 |
+
class RuntimeDependency:
|
| 19 |
+
"""Represents a runtime dependency for a language server."""
|
| 20 |
+
|
| 21 |
+
id: str
|
| 22 |
+
platform_id: str | None = None
|
| 23 |
+
url: str | None = None
|
| 24 |
+
archive_type: str | None = None
|
| 25 |
+
binary_name: str | None = None
|
| 26 |
+
command: str | list[str] | None = None
|
| 27 |
+
package_name: str | None = None
|
| 28 |
+
package_version: str | None = None
|
| 29 |
+
extract_path: str | None = None
|
| 30 |
+
description: str | None = None
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class RuntimeDependencyCollection:
|
| 34 |
+
"""Utility to handle installation of runtime dependencies."""
|
| 35 |
+
|
| 36 |
+
def __init__(self, dependencies: Sequence[RuntimeDependency]):
|
| 37 |
+
self._dependencies = list(dependencies)
|
| 38 |
+
|
| 39 |
+
def for_platform(self, platform_id: str) -> list[RuntimeDependency]:
|
| 40 |
+
return [d for d in self._dependencies if d.platform_id in (platform_id, "any", "platform-agnostic", None)]
|
| 41 |
+
|
| 42 |
+
def for_current_platform(self) -> list[RuntimeDependency]:
|
| 43 |
+
return self.for_platform(PlatformUtils.get_platform_id().value)
|
| 44 |
+
|
| 45 |
+
def single_for_current_platform(self) -> RuntimeDependency:
|
| 46 |
+
deps = self.for_current_platform()
|
| 47 |
+
if len(deps) != 1:
|
| 48 |
+
raise RuntimeError(f"Expected exactly one runtime dependency for {PlatformUtils.get_platform_id().value}, found {len(deps)}")
|
| 49 |
+
return deps[0]
|
| 50 |
+
|
| 51 |
+
def binary_path(self, target_dir: str) -> str:
|
| 52 |
+
dep = self.single_for_current_platform()
|
| 53 |
+
if not dep.binary_name:
|
| 54 |
+
return target_dir
|
| 55 |
+
return os.path.join(target_dir, dep.binary_name)
|
| 56 |
+
|
| 57 |
+
def install(self, logger: LanguageServerLogger, target_dir: str) -> dict[str, str]:
|
| 58 |
+
"""Install all dependencies for the current platform into *target_dir*.
|
| 59 |
+
|
| 60 |
+
Returns a mapping from dependency id to the resolved binary path.
|
| 61 |
+
"""
|
| 62 |
+
os.makedirs(target_dir, exist_ok=True)
|
| 63 |
+
results: dict[str, str] = {}
|
| 64 |
+
for dep in self.for_current_platform():
|
| 65 |
+
if dep.url:
|
| 66 |
+
self._install_from_url(dep, logger, target_dir)
|
| 67 |
+
if dep.command:
|
| 68 |
+
self._run_command(dep.command, target_dir)
|
| 69 |
+
if dep.binary_name:
|
| 70 |
+
results[dep.id] = os.path.join(target_dir, dep.binary_name)
|
| 71 |
+
else:
|
| 72 |
+
results[dep.id] = target_dir
|
| 73 |
+
return results
|
| 74 |
+
|
| 75 |
+
@staticmethod
|
| 76 |
+
def _run_command(command: str | list[str], cwd: str) -> None:
|
| 77 |
+
kwargs = subprocess_kwargs()
|
| 78 |
+
if not PlatformUtils.get_platform_id().is_windows():
|
| 79 |
+
import pwd
|
| 80 |
+
|
| 81 |
+
kwargs["user"] = pwd.getpwuid(os.getuid()).pw_name
|
| 82 |
+
|
| 83 |
+
is_windows = platform.system() == "Windows"
|
| 84 |
+
if not isinstance(command, str) and not is_windows:
|
| 85 |
+
# Since we are using the shell, we need to convert the command list to a single string
|
| 86 |
+
# on Linux/macOS
|
| 87 |
+
command = " ".join(command)
|
| 88 |
+
|
| 89 |
+
log.info("Running command %s in '%s'", f"'{command}'" if isinstance(command, str) else command, cwd)
|
| 90 |
+
|
| 91 |
+
completed_process = subprocess.run(
|
| 92 |
+
command,
|
| 93 |
+
shell=True,
|
| 94 |
+
check=True,
|
| 95 |
+
cwd=cwd,
|
| 96 |
+
stdout=subprocess.PIPE,
|
| 97 |
+
stderr=subprocess.STDOUT,
|
| 98 |
+
**kwargs,
|
| 99 |
+
)
|
| 100 |
+
if completed_process.returncode != 0:
|
| 101 |
+
log.warning("Command '%s' failed with return code %d", command, completed_process.returncode)
|
| 102 |
+
log.warning("Command output:\n%s", completed_process.stdout)
|
| 103 |
+
else:
|
| 104 |
+
log.info(
|
| 105 |
+
"Command completed successfully",
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
@staticmethod
|
| 109 |
+
def _install_from_url(dep: RuntimeDependency, logger: LanguageServerLogger, target_dir: str) -> None:
|
| 110 |
+
if dep.archive_type == "gz" and dep.binary_name:
|
| 111 |
+
dest = os.path.join(target_dir, dep.binary_name)
|
| 112 |
+
FileUtils.download_and_extract_archive(logger, dep.url, dest, dep.archive_type)
|
| 113 |
+
else:
|
| 114 |
+
FileUtils.download_and_extract_archive(logger, dep.url, target_dir, dep.archive_type or "zip")
|
projects/ui/serena-new/src/solidlsp/language_servers/csharp_language_server.py
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
CSharp Language Server using Microsoft.CodeAnalysis.LanguageServer (Official Roslyn-based LSP server)
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import platform
|
| 9 |
+
import shutil
|
| 10 |
+
import subprocess
|
| 11 |
+
import tarfile
|
| 12 |
+
import threading
|
| 13 |
+
import urllib.request
|
| 14 |
+
import zipfile
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
from typing import cast
|
| 17 |
+
|
| 18 |
+
from overrides import override
|
| 19 |
+
|
| 20 |
+
from solidlsp.ls import SolidLanguageServer
|
| 21 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 22 |
+
from solidlsp.ls_exceptions import SolidLSPException
|
| 23 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 24 |
+
from solidlsp.ls_utils import PathUtils
|
| 25 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 26 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 27 |
+
from solidlsp.settings import SolidLSPSettings
|
| 28 |
+
from solidlsp.util.zip import SafeZipExtractor
|
| 29 |
+
|
| 30 |
+
from .common import RuntimeDependency
|
| 31 |
+
|
| 32 |
+
# Runtime dependencies configuration
|
| 33 |
+
RUNTIME_DEPENDENCIES = [
|
| 34 |
+
RuntimeDependency(
|
| 35 |
+
id="CSharpLanguageServer",
|
| 36 |
+
description="Microsoft.CodeAnalysis.LanguageServer for Windows (x64)",
|
| 37 |
+
package_name="Microsoft.CodeAnalysis.LanguageServer.win-x64",
|
| 38 |
+
package_version="5.0.0-1.25329.6",
|
| 39 |
+
platform_id="win-x64",
|
| 40 |
+
archive_type="nupkg",
|
| 41 |
+
binary_name="Microsoft.CodeAnalysis.LanguageServer.dll",
|
| 42 |
+
extract_path="content/LanguageServer/win-x64",
|
| 43 |
+
),
|
| 44 |
+
RuntimeDependency(
|
| 45 |
+
id="CSharpLanguageServer",
|
| 46 |
+
description="Microsoft.CodeAnalysis.LanguageServer for Windows (ARM64)",
|
| 47 |
+
package_name="Microsoft.CodeAnalysis.LanguageServer.win-arm64",
|
| 48 |
+
package_version="5.0.0-1.25329.6",
|
| 49 |
+
platform_id="win-arm64",
|
| 50 |
+
archive_type="nupkg",
|
| 51 |
+
binary_name="Microsoft.CodeAnalysis.LanguageServer.dll",
|
| 52 |
+
extract_path="content/LanguageServer/win-arm64",
|
| 53 |
+
),
|
| 54 |
+
RuntimeDependency(
|
| 55 |
+
id="CSharpLanguageServer",
|
| 56 |
+
description="Microsoft.CodeAnalysis.LanguageServer for macOS (x64)",
|
| 57 |
+
package_name="Microsoft.CodeAnalysis.LanguageServer.osx-x64",
|
| 58 |
+
package_version="5.0.0-1.25329.6",
|
| 59 |
+
platform_id="osx-x64",
|
| 60 |
+
archive_type="nupkg",
|
| 61 |
+
binary_name="Microsoft.CodeAnalysis.LanguageServer.dll",
|
| 62 |
+
extract_path="content/LanguageServer/osx-x64",
|
| 63 |
+
),
|
| 64 |
+
RuntimeDependency(
|
| 65 |
+
id="CSharpLanguageServer",
|
| 66 |
+
description="Microsoft.CodeAnalysis.LanguageServer for macOS (ARM64)",
|
| 67 |
+
package_name="Microsoft.CodeAnalysis.LanguageServer.osx-arm64",
|
| 68 |
+
package_version="5.0.0-1.25329.6",
|
| 69 |
+
platform_id="osx-arm64",
|
| 70 |
+
archive_type="nupkg",
|
| 71 |
+
binary_name="Microsoft.CodeAnalysis.LanguageServer.dll",
|
| 72 |
+
extract_path="content/LanguageServer/osx-arm64",
|
| 73 |
+
),
|
| 74 |
+
RuntimeDependency(
|
| 75 |
+
id="CSharpLanguageServer",
|
| 76 |
+
description="Microsoft.CodeAnalysis.LanguageServer for Linux (x64)",
|
| 77 |
+
package_name="Microsoft.CodeAnalysis.LanguageServer.linux-x64",
|
| 78 |
+
package_version="5.0.0-1.25329.6",
|
| 79 |
+
platform_id="linux-x64",
|
| 80 |
+
archive_type="nupkg",
|
| 81 |
+
binary_name="Microsoft.CodeAnalysis.LanguageServer.dll",
|
| 82 |
+
extract_path="content/LanguageServer/linux-x64",
|
| 83 |
+
),
|
| 84 |
+
RuntimeDependency(
|
| 85 |
+
id="CSharpLanguageServer",
|
| 86 |
+
description="Microsoft.CodeAnalysis.LanguageServer for Linux (ARM64)",
|
| 87 |
+
package_name="Microsoft.CodeAnalysis.LanguageServer.linux-arm64",
|
| 88 |
+
package_version="5.0.0-1.25329.6",
|
| 89 |
+
platform_id="linux-arm64",
|
| 90 |
+
archive_type="nupkg",
|
| 91 |
+
binary_name="Microsoft.CodeAnalysis.LanguageServer.dll",
|
| 92 |
+
extract_path="content/LanguageServer/linux-arm64",
|
| 93 |
+
),
|
| 94 |
+
RuntimeDependency(
|
| 95 |
+
id="DotNetRuntime",
|
| 96 |
+
description=".NET 9 Runtime for Windows (x64)",
|
| 97 |
+
url="https://builds.dotnet.microsoft.com/dotnet/Runtime/9.0.6/dotnet-runtime-9.0.6-win-x64.zip",
|
| 98 |
+
platform_id="win-x64",
|
| 99 |
+
archive_type="zip",
|
| 100 |
+
binary_name="dotnet.exe",
|
| 101 |
+
),
|
| 102 |
+
RuntimeDependency(
|
| 103 |
+
id="DotNetRuntime",
|
| 104 |
+
description=".NET 9 Runtime for Linux (x64)",
|
| 105 |
+
url="https://builds.dotnet.microsoft.com/dotnet/Runtime/9.0.6/dotnet-runtime-9.0.6-linux-x64.tar.gz",
|
| 106 |
+
platform_id="linux-x64",
|
| 107 |
+
archive_type="tar.gz",
|
| 108 |
+
binary_name="dotnet",
|
| 109 |
+
),
|
| 110 |
+
RuntimeDependency(
|
| 111 |
+
id="DotNetRuntime",
|
| 112 |
+
description=".NET 9 Runtime for macOS (x64)",
|
| 113 |
+
url="https://builds.dotnet.microsoft.com/dotnet/Runtime/9.0.6/dotnet-runtime-9.0.6-osx-x64.tar.gz",
|
| 114 |
+
platform_id="osx-x64",
|
| 115 |
+
archive_type="tar.gz",
|
| 116 |
+
binary_name="dotnet",
|
| 117 |
+
),
|
| 118 |
+
RuntimeDependency(
|
| 119 |
+
id="DotNetRuntime",
|
| 120 |
+
description=".NET 9 Runtime for macOS (ARM64)",
|
| 121 |
+
url="https://builds.dotnet.microsoft.com/dotnet/Runtime/9.0.6/dotnet-runtime-9.0.6-osx-arm64.tar.gz",
|
| 122 |
+
platform_id="osx-arm64",
|
| 123 |
+
archive_type="tar.gz",
|
| 124 |
+
binary_name="dotnet",
|
| 125 |
+
),
|
| 126 |
+
]
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def breadth_first_file_scan(root_dir):
|
| 130 |
+
"""
|
| 131 |
+
Perform a breadth-first scan of files in the given directory.
|
| 132 |
+
Yields file paths in breadth-first order.
|
| 133 |
+
"""
|
| 134 |
+
queue = [root_dir]
|
| 135 |
+
while queue:
|
| 136 |
+
current_dir = queue.pop(0)
|
| 137 |
+
try:
|
| 138 |
+
for item in os.listdir(current_dir):
|
| 139 |
+
if item.startswith("."):
|
| 140 |
+
continue
|
| 141 |
+
item_path = os.path.join(current_dir, item)
|
| 142 |
+
if os.path.isdir(item_path):
|
| 143 |
+
queue.append(item_path)
|
| 144 |
+
elif os.path.isfile(item_path):
|
| 145 |
+
yield item_path
|
| 146 |
+
except (PermissionError, OSError):
|
| 147 |
+
# Skip directories we can't access
|
| 148 |
+
pass
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def find_solution_or_project_file(root_dir) -> str | None:
|
| 152 |
+
"""
|
| 153 |
+
Find the first .sln file in breadth-first order.
|
| 154 |
+
If no .sln file is found, look for a .csproj file.
|
| 155 |
+
"""
|
| 156 |
+
sln_file = None
|
| 157 |
+
csproj_file = None
|
| 158 |
+
|
| 159 |
+
for filename in breadth_first_file_scan(root_dir):
|
| 160 |
+
if filename.endswith(".sln") and sln_file is None:
|
| 161 |
+
sln_file = filename
|
| 162 |
+
elif filename.endswith(".csproj") and csproj_file is None:
|
| 163 |
+
csproj_file = filename
|
| 164 |
+
|
| 165 |
+
# If we found a .sln file, return it immediately
|
| 166 |
+
if sln_file:
|
| 167 |
+
return sln_file
|
| 168 |
+
|
| 169 |
+
# If no .sln file was found, return the first .csproj file
|
| 170 |
+
return csproj_file
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
class CSharpLanguageServer(SolidLanguageServer):
|
| 174 |
+
"""
|
| 175 |
+
Provides C# specific instantiation of the LanguageServer class using Microsoft.CodeAnalysis.LanguageServer.
|
| 176 |
+
This is the official Roslyn-based language server from Microsoft.
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
def __init__(
|
| 180 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 181 |
+
):
|
| 182 |
+
"""
|
| 183 |
+
Creates a CSharpLanguageServer instance. This class is not meant to be instantiated directly.
|
| 184 |
+
Use LanguageServer.create() instead.
|
| 185 |
+
"""
|
| 186 |
+
dotnet_path, language_server_path = self._ensure_server_installed(logger, config, solidlsp_settings)
|
| 187 |
+
|
| 188 |
+
# Find solution or project file
|
| 189 |
+
solution_or_project = find_solution_or_project_file(repository_root_path)
|
| 190 |
+
|
| 191 |
+
# Create log directory
|
| 192 |
+
log_dir = Path(self.ls_resources_dir(solidlsp_settings)) / "logs"
|
| 193 |
+
log_dir.mkdir(parents=True, exist_ok=True)
|
| 194 |
+
|
| 195 |
+
# Build command using dotnet directly
|
| 196 |
+
cmd = [dotnet_path, language_server_path, "--logLevel=Information", f"--extensionLogDirectory={log_dir}", "--stdio"]
|
| 197 |
+
|
| 198 |
+
# The language server will discover the solution/project from the workspace root
|
| 199 |
+
if solution_or_project:
|
| 200 |
+
logger.log(f"Found solution/project file: {solution_or_project}", logging.INFO)
|
| 201 |
+
else:
|
| 202 |
+
logger.log("No .sln or .csproj file found, language server will attempt auto-discovery", logging.WARNING)
|
| 203 |
+
|
| 204 |
+
logger.log(f"Language server command: {' '.join(cmd)}", logging.DEBUG)
|
| 205 |
+
|
| 206 |
+
super().__init__(
|
| 207 |
+
config,
|
| 208 |
+
logger,
|
| 209 |
+
repository_root_path,
|
| 210 |
+
ProcessLaunchInfo(cmd=cmd, cwd=repository_root_path),
|
| 211 |
+
"csharp",
|
| 212 |
+
solidlsp_settings,
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
self.initialization_complete = threading.Event()
|
| 216 |
+
|
| 217 |
+
@override
|
| 218 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 219 |
+
return super().is_ignored_dirname(dirname) or dirname in ["bin", "obj", "packages", ".vs"]
|
| 220 |
+
|
| 221 |
+
@classmethod
|
| 222 |
+
def _ensure_server_installed(
|
| 223 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 224 |
+
) -> tuple[str, str]:
|
| 225 |
+
"""
|
| 226 |
+
Ensure .NET runtime and Microsoft.CodeAnalysis.LanguageServer are available.
|
| 227 |
+
Returns a tuple of (dotnet_path, language_server_dll_path).
|
| 228 |
+
"""
|
| 229 |
+
runtime_id = CSharpLanguageServer._get_runtime_id()
|
| 230 |
+
lang_server_dep, dotnet_runtime_dep = CSharpLanguageServer._get_runtime_dependencies(runtime_id)
|
| 231 |
+
dotnet_path = CSharpLanguageServer._ensure_dotnet_runtime(logger, dotnet_runtime_dep, solidlsp_settings)
|
| 232 |
+
server_dll_path = CSharpLanguageServer._ensure_language_server(logger, lang_server_dep, solidlsp_settings)
|
| 233 |
+
|
| 234 |
+
return dotnet_path, server_dll_path
|
| 235 |
+
|
| 236 |
+
@staticmethod
|
| 237 |
+
def _get_runtime_id() -> str:
|
| 238 |
+
"""Determine the runtime ID based on the platform."""
|
| 239 |
+
system = platform.system().lower()
|
| 240 |
+
machine = platform.machine().lower()
|
| 241 |
+
|
| 242 |
+
if system == "windows":
|
| 243 |
+
return "win-x64" if machine in ["amd64", "x86_64"] else "win-arm64"
|
| 244 |
+
elif system == "darwin":
|
| 245 |
+
return "osx-x64" if machine in ["x86_64"] else "osx-arm64"
|
| 246 |
+
elif system == "linux":
|
| 247 |
+
return "linux-x64" if machine in ["x86_64", "amd64"] else "linux-arm64"
|
| 248 |
+
else:
|
| 249 |
+
raise SolidLSPException(f"Unsupported platform: {system} {machine}")
|
| 250 |
+
|
| 251 |
+
@staticmethod
|
| 252 |
+
def _get_runtime_dependencies(runtime_id: str) -> tuple[RuntimeDependency, RuntimeDependency]:
|
| 253 |
+
"""Get the language server and .NET runtime dependencies for the platform."""
|
| 254 |
+
lang_server_dep = None
|
| 255 |
+
dotnet_runtime_dep = None
|
| 256 |
+
|
| 257 |
+
for dep in RUNTIME_DEPENDENCIES:
|
| 258 |
+
if dep.id == "CSharpLanguageServer" and dep.platform_id == runtime_id:
|
| 259 |
+
lang_server_dep = dep
|
| 260 |
+
elif dep.id == "DotNetRuntime" and dep.platform_id == runtime_id:
|
| 261 |
+
dotnet_runtime_dep = dep
|
| 262 |
+
|
| 263 |
+
if not lang_server_dep:
|
| 264 |
+
raise SolidLSPException(f"No C# language server dependency found for platform {runtime_id}")
|
| 265 |
+
if not dotnet_runtime_dep:
|
| 266 |
+
raise SolidLSPException(f"No .NET runtime dependency found for platform {runtime_id}")
|
| 267 |
+
|
| 268 |
+
return lang_server_dep, dotnet_runtime_dep
|
| 269 |
+
|
| 270 |
+
@classmethod
|
| 271 |
+
def _ensure_dotnet_runtime(
|
| 272 |
+
cls, logger: LanguageServerLogger, runtime_dep: RuntimeDependency, solidlsp_settings: SolidLSPSettings
|
| 273 |
+
) -> str:
|
| 274 |
+
"""Ensure .NET runtime is available and return the dotnet executable path."""
|
| 275 |
+
# Check if dotnet is already available on the system
|
| 276 |
+
system_dotnet = shutil.which("dotnet")
|
| 277 |
+
if system_dotnet:
|
| 278 |
+
# Check if it's .NET 9
|
| 279 |
+
try:
|
| 280 |
+
result = subprocess.run([system_dotnet, "--list-runtimes"], capture_output=True, text=True, check=True)
|
| 281 |
+
if "Microsoft.NETCore.App 9." in result.stdout:
|
| 282 |
+
logger.log("Found system .NET 9 runtime", logging.INFO)
|
| 283 |
+
return system_dotnet
|
| 284 |
+
except subprocess.CalledProcessError:
|
| 285 |
+
pass
|
| 286 |
+
|
| 287 |
+
# Download .NET 9 runtime using config
|
| 288 |
+
return cls._ensure_dotnet_runtime_from_config(logger, runtime_dep, solidlsp_settings)
|
| 289 |
+
|
| 290 |
+
@classmethod
|
| 291 |
+
def _ensure_language_server(
|
| 292 |
+
cls, logger: LanguageServerLogger, lang_server_dep: RuntimeDependency, solidlsp_settings: SolidLSPSettings
|
| 293 |
+
) -> str:
|
| 294 |
+
"""Ensure language server is available and return the DLL path."""
|
| 295 |
+
package_name = lang_server_dep.package_name
|
| 296 |
+
package_version = lang_server_dep.package_version
|
| 297 |
+
|
| 298 |
+
server_dir = Path(cls.ls_resources_dir(solidlsp_settings)) / f"{package_name}.{package_version}"
|
| 299 |
+
server_dll = server_dir / lang_server_dep.binary_name
|
| 300 |
+
|
| 301 |
+
if server_dll.exists():
|
| 302 |
+
logger.log(f"Using cached Microsoft.CodeAnalysis.LanguageServer from {server_dll}", logging.INFO)
|
| 303 |
+
return str(server_dll)
|
| 304 |
+
|
| 305 |
+
# Download and install the language server
|
| 306 |
+
logger.log(f"Downloading {package_name} version {package_version}...", logging.INFO)
|
| 307 |
+
package_path = cls._download_nuget_package_direct(logger, package_name, package_version, solidlsp_settings)
|
| 308 |
+
|
| 309 |
+
# Extract and install
|
| 310 |
+
cls._extract_language_server(lang_server_dep, package_path, server_dir)
|
| 311 |
+
|
| 312 |
+
if not server_dll.exists():
|
| 313 |
+
raise SolidLSPException("Microsoft.CodeAnalysis.LanguageServer.dll not found after extraction")
|
| 314 |
+
|
| 315 |
+
# Make executable on Unix systems
|
| 316 |
+
if platform.system().lower() != "windows":
|
| 317 |
+
server_dll.chmod(0o755)
|
| 318 |
+
|
| 319 |
+
logger.log(f"Successfully installed Microsoft.CodeAnalysis.LanguageServer to {server_dll}", logging.INFO)
|
| 320 |
+
return str(server_dll)
|
| 321 |
+
|
| 322 |
+
@staticmethod
|
| 323 |
+
def _extract_language_server(lang_server_dep: RuntimeDependency, package_path: Path, server_dir: Path) -> None:
|
| 324 |
+
"""Extract language server files from downloaded package."""
|
| 325 |
+
extract_path = lang_server_dep.extract_path or "lib/net9.0"
|
| 326 |
+
source_dir = package_path / extract_path
|
| 327 |
+
|
| 328 |
+
if not source_dir.exists():
|
| 329 |
+
# Try alternative locations
|
| 330 |
+
for possible_dir in [
|
| 331 |
+
package_path / "tools" / "net9.0" / "any",
|
| 332 |
+
package_path / "lib" / "net9.0",
|
| 333 |
+
package_path / "contentFiles" / "any" / "net9.0",
|
| 334 |
+
]:
|
| 335 |
+
if possible_dir.exists():
|
| 336 |
+
source_dir = possible_dir
|
| 337 |
+
break
|
| 338 |
+
else:
|
| 339 |
+
raise SolidLSPException(f"Could not find language server files in package. Searched in {package_path}")
|
| 340 |
+
|
| 341 |
+
# Copy files to cache directory
|
| 342 |
+
server_dir.mkdir(parents=True, exist_ok=True)
|
| 343 |
+
shutil.copytree(source_dir, server_dir, dirs_exist_ok=True)
|
| 344 |
+
|
| 345 |
+
@classmethod
|
| 346 |
+
def _download_nuget_package_direct(
|
| 347 |
+
cls, logger: LanguageServerLogger, package_name: str, package_version: str, solidlsp_settings: SolidLSPSettings
|
| 348 |
+
) -> Path:
|
| 349 |
+
"""
|
| 350 |
+
Download a NuGet package directly from the Azure NuGet feed.
|
| 351 |
+
Returns the path to the extracted package directory.
|
| 352 |
+
"""
|
| 353 |
+
azure_feed_url = "https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json"
|
| 354 |
+
|
| 355 |
+
# Create temporary directory for package download
|
| 356 |
+
temp_dir = Path(cls.ls_resources_dir(solidlsp_settings)) / "temp_downloads"
|
| 357 |
+
temp_dir.mkdir(parents=True, exist_ok=True)
|
| 358 |
+
|
| 359 |
+
try:
|
| 360 |
+
# First, get the service index from the Azure feed
|
| 361 |
+
logger.log("Fetching NuGet service index from Azure feed...", logging.DEBUG)
|
| 362 |
+
with urllib.request.urlopen(azure_feed_url) as response:
|
| 363 |
+
service_index = json.loads(response.read().decode())
|
| 364 |
+
|
| 365 |
+
# Find the package base address (for downloading packages)
|
| 366 |
+
package_base_address = None
|
| 367 |
+
for resource in service_index.get("resources", []):
|
| 368 |
+
if resource.get("@type") == "PackageBaseAddress/3.0.0":
|
| 369 |
+
package_base_address = resource.get("@id")
|
| 370 |
+
break
|
| 371 |
+
|
| 372 |
+
if not package_base_address:
|
| 373 |
+
raise SolidLSPException("Could not find package base address in Azure NuGet feed")
|
| 374 |
+
|
| 375 |
+
# Construct the download URL for the specific package
|
| 376 |
+
package_id_lower = package_name.lower()
|
| 377 |
+
package_version_lower = package_version.lower()
|
| 378 |
+
package_url = f"{package_base_address.rstrip('/')}/{package_id_lower}/{package_version_lower}/{package_id_lower}.{package_version_lower}.nupkg"
|
| 379 |
+
|
| 380 |
+
logger.log(f"Downloading package from: {package_url}", logging.DEBUG)
|
| 381 |
+
|
| 382 |
+
# Download the .nupkg file
|
| 383 |
+
nupkg_file = temp_dir / f"{package_name}.{package_version}.nupkg"
|
| 384 |
+
urllib.request.urlretrieve(package_url, nupkg_file)
|
| 385 |
+
|
| 386 |
+
# Extract the .nupkg file (it's just a zip file)
|
| 387 |
+
package_extract_dir = temp_dir / f"{package_name}.{package_version}"
|
| 388 |
+
package_extract_dir.mkdir(exist_ok=True)
|
| 389 |
+
|
| 390 |
+
# Use SafeZipExtractor to handle long paths and skip errors
|
| 391 |
+
extractor = SafeZipExtractor(archive_path=nupkg_file, extract_dir=package_extract_dir, verbose=False)
|
| 392 |
+
extractor.extract_all()
|
| 393 |
+
|
| 394 |
+
# Clean up the nupkg file
|
| 395 |
+
nupkg_file.unlink()
|
| 396 |
+
|
| 397 |
+
logger.log(f"Successfully downloaded and extracted {package_name} version {package_version}", logging.INFO)
|
| 398 |
+
return package_extract_dir
|
| 399 |
+
|
| 400 |
+
except Exception as e:
|
| 401 |
+
raise SolidLSPException(
|
| 402 |
+
f"Failed to download package {package_name} version {package_version} from Azure NuGet feed: {e}"
|
| 403 |
+
) from e
|
| 404 |
+
|
| 405 |
+
@classmethod
|
| 406 |
+
def _ensure_dotnet_runtime_from_config(
|
| 407 |
+
cls, logger: LanguageServerLogger, runtime_dep: RuntimeDependency, solidlsp_settings: SolidLSPSettings
|
| 408 |
+
) -> str:
|
| 409 |
+
"""
|
| 410 |
+
Ensure .NET 9 runtime is available using runtime dependency configuration.
|
| 411 |
+
Returns the path to the dotnet executable.
|
| 412 |
+
"""
|
| 413 |
+
# Check if dotnet is already available on the system
|
| 414 |
+
system_dotnet = shutil.which("dotnet")
|
| 415 |
+
if system_dotnet:
|
| 416 |
+
# Check if it's .NET 9
|
| 417 |
+
try:
|
| 418 |
+
result = subprocess.run([system_dotnet, "--list-runtimes"], capture_output=True, text=True, check=True)
|
| 419 |
+
if "Microsoft.NETCore.App 9." in result.stdout:
|
| 420 |
+
logger.log("Found system .NET 9 runtime", logging.INFO)
|
| 421 |
+
return system_dotnet
|
| 422 |
+
except subprocess.CalledProcessError:
|
| 423 |
+
pass
|
| 424 |
+
|
| 425 |
+
# Download .NET 9 runtime using config
|
| 426 |
+
dotnet_dir = Path(cls.ls_resources_dir(solidlsp_settings)) / "dotnet-runtime-9.0"
|
| 427 |
+
dotnet_exe = dotnet_dir / runtime_dep.binary_name
|
| 428 |
+
|
| 429 |
+
if dotnet_exe.exists():
|
| 430 |
+
logger.log(f"Using cached .NET runtime from {dotnet_exe}", logging.INFO)
|
| 431 |
+
return str(dotnet_exe)
|
| 432 |
+
|
| 433 |
+
# Download .NET runtime
|
| 434 |
+
logger.log("Downloading .NET 9 runtime...", logging.INFO)
|
| 435 |
+
dotnet_dir.mkdir(parents=True, exist_ok=True)
|
| 436 |
+
|
| 437 |
+
url = runtime_dep.url
|
| 438 |
+
archive_type = runtime_dep.archive_type
|
| 439 |
+
|
| 440 |
+
# Download the runtime
|
| 441 |
+
download_path = dotnet_dir / f"dotnet-runtime.{archive_type}"
|
| 442 |
+
try:
|
| 443 |
+
logger.log(f"Downloading from {url}", logging.DEBUG)
|
| 444 |
+
urllib.request.urlretrieve(url, download_path)
|
| 445 |
+
|
| 446 |
+
# Extract the archive
|
| 447 |
+
if archive_type == "zip":
|
| 448 |
+
with zipfile.ZipFile(download_path, "r") as zip_ref:
|
| 449 |
+
zip_ref.extractall(dotnet_dir)
|
| 450 |
+
else:
|
| 451 |
+
# tar.gz
|
| 452 |
+
with tarfile.open(download_path, "r:gz") as tar_ref:
|
| 453 |
+
tar_ref.extractall(dotnet_dir)
|
| 454 |
+
|
| 455 |
+
# Remove the archive
|
| 456 |
+
download_path.unlink()
|
| 457 |
+
|
| 458 |
+
# Make dotnet executable on Unix
|
| 459 |
+
if platform.system().lower() != "windows":
|
| 460 |
+
dotnet_exe.chmod(0o755)
|
| 461 |
+
|
| 462 |
+
logger.log(f"Successfully installed .NET 9 runtime to {dotnet_exe}", logging.INFO)
|
| 463 |
+
return str(dotnet_exe)
|
| 464 |
+
|
| 465 |
+
except Exception as e:
|
| 466 |
+
raise SolidLSPException(f"Failed to download .NET 9 runtime from {url}: {e}") from e
|
| 467 |
+
|
| 468 |
+
def _get_initialize_params(self) -> InitializeParams:
|
| 469 |
+
"""
|
| 470 |
+
Returns the initialize params for the Microsoft.CodeAnalysis.LanguageServer.
|
| 471 |
+
"""
|
| 472 |
+
root_uri = PathUtils.path_to_uri(self.repository_root_path)
|
| 473 |
+
root_name = os.path.basename(self.repository_root_path)
|
| 474 |
+
return cast(
|
| 475 |
+
InitializeParams,
|
| 476 |
+
{
|
| 477 |
+
"workspaceFolders": [{"uri": root_uri, "name": root_name}],
|
| 478 |
+
"processId": os.getpid(),
|
| 479 |
+
"rootPath": self.repository_root_path,
|
| 480 |
+
"rootUri": root_uri,
|
| 481 |
+
"capabilities": {
|
| 482 |
+
"window": {
|
| 483 |
+
"workDoneProgress": True,
|
| 484 |
+
"showMessage": {"messageActionItem": {"additionalPropertiesSupport": True}},
|
| 485 |
+
"showDocument": {"support": True},
|
| 486 |
+
},
|
| 487 |
+
"workspace": {
|
| 488 |
+
"applyEdit": True,
|
| 489 |
+
"workspaceEdit": {"documentChanges": True},
|
| 490 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 491 |
+
"didChangeWatchedFiles": {"dynamicRegistration": True},
|
| 492 |
+
"symbol": {
|
| 493 |
+
"dynamicRegistration": True,
|
| 494 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 495 |
+
},
|
| 496 |
+
"executeCommand": {"dynamicRegistration": True},
|
| 497 |
+
"configuration": True,
|
| 498 |
+
"workspaceFolders": True,
|
| 499 |
+
"workDoneProgress": True,
|
| 500 |
+
},
|
| 501 |
+
"textDocument": {
|
| 502 |
+
"synchronization": {"dynamicRegistration": True, "willSave": True, "willSaveWaitUntil": True, "didSave": True},
|
| 503 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 504 |
+
"signatureHelp": {
|
| 505 |
+
"dynamicRegistration": True,
|
| 506 |
+
"signatureInformation": {
|
| 507 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 508 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 509 |
+
},
|
| 510 |
+
},
|
| 511 |
+
"definition": {"dynamicRegistration": True},
|
| 512 |
+
"references": {"dynamicRegistration": True},
|
| 513 |
+
"documentSymbol": {
|
| 514 |
+
"dynamicRegistration": True,
|
| 515 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 516 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 517 |
+
},
|
| 518 |
+
},
|
| 519 |
+
},
|
| 520 |
+
},
|
| 521 |
+
)
|
| 522 |
+
|
| 523 |
+
def _start_server(self):
|
| 524 |
+
def do_nothing(params):
|
| 525 |
+
return
|
| 526 |
+
|
| 527 |
+
def window_log_message(msg):
|
| 528 |
+
"""Log messages from the language server."""
|
| 529 |
+
message_text = msg.get("message", "")
|
| 530 |
+
level = msg.get("type", 4) # Default to Log level
|
| 531 |
+
|
| 532 |
+
# Map LSP message types to Python logging levels
|
| 533 |
+
level_map = {1: logging.ERROR, 2: logging.WARNING, 3: logging.INFO, 4: logging.DEBUG} # Error # Warning # Info # Log
|
| 534 |
+
|
| 535 |
+
self.logger.log(f"LSP: {message_text}", level_map.get(level, logging.DEBUG))
|
| 536 |
+
|
| 537 |
+
def handle_progress(params):
|
| 538 |
+
"""Handle progress notifications from the language server."""
|
| 539 |
+
token = params.get("token", "")
|
| 540 |
+
value = params.get("value", {})
|
| 541 |
+
|
| 542 |
+
# Log raw progress for debugging
|
| 543 |
+
self.logger.log(f"Progress notification received: {params}", logging.DEBUG)
|
| 544 |
+
|
| 545 |
+
# Handle different progress notification types
|
| 546 |
+
kind = value.get("kind")
|
| 547 |
+
|
| 548 |
+
if kind == "begin":
|
| 549 |
+
title = value.get("title", "Operation in progress")
|
| 550 |
+
message = value.get("message", "")
|
| 551 |
+
percentage = value.get("percentage")
|
| 552 |
+
|
| 553 |
+
if percentage is not None:
|
| 554 |
+
self.logger.log(f"Progress [{token}]: {title} - {message} ({percentage}%)", logging.INFO)
|
| 555 |
+
else:
|
| 556 |
+
self.logger.log(f"Progress [{token}]: {title} - {message}", logging.INFO)
|
| 557 |
+
|
| 558 |
+
elif kind == "report":
|
| 559 |
+
message = value.get("message", "")
|
| 560 |
+
percentage = value.get("percentage")
|
| 561 |
+
|
| 562 |
+
if percentage is not None:
|
| 563 |
+
self.logger.log(f"Progress [{token}]: {message} ({percentage}%)", logging.INFO)
|
| 564 |
+
elif message:
|
| 565 |
+
self.logger.log(f"Progress [{token}]: {message}", logging.INFO)
|
| 566 |
+
|
| 567 |
+
elif kind == "end":
|
| 568 |
+
message = value.get("message", "Operation completed")
|
| 569 |
+
self.logger.log(f"Progress [{token}]: {message}", logging.INFO)
|
| 570 |
+
|
| 571 |
+
def handle_workspace_configuration(params):
|
| 572 |
+
"""Handle workspace/configuration requests from the server."""
|
| 573 |
+
items = params.get("items", [])
|
| 574 |
+
result = []
|
| 575 |
+
|
| 576 |
+
for item in items:
|
| 577 |
+
section = item.get("section", "")
|
| 578 |
+
|
| 579 |
+
# Provide default values based on the configuration section
|
| 580 |
+
if section.startswith(("dotnet", "csharp")):
|
| 581 |
+
# Default configuration for C# settings
|
| 582 |
+
if "enable" in section or "show" in section or "suppress" in section or "navigate" in section:
|
| 583 |
+
# Boolean settings
|
| 584 |
+
result.append(False)
|
| 585 |
+
elif "scope" in section:
|
| 586 |
+
# Scope settings - use appropriate enum values
|
| 587 |
+
if "analyzer_diagnostics_scope" in section:
|
| 588 |
+
result.append("openFiles") # BackgroundAnalysisScope
|
| 589 |
+
elif "compiler_diagnostics_scope" in section:
|
| 590 |
+
result.append("openFiles") # CompilerDiagnosticsScope
|
| 591 |
+
else:
|
| 592 |
+
result.append("openFiles")
|
| 593 |
+
elif section == "dotnet_member_insertion_location":
|
| 594 |
+
# ImplementTypeInsertionBehavior enum
|
| 595 |
+
result.append("with_other_members_of_the_same_kind")
|
| 596 |
+
elif section == "dotnet_property_generation_behavior":
|
| 597 |
+
# ImplementTypePropertyGenerationBehavior enum
|
| 598 |
+
result.append("prefer_throwing_properties")
|
| 599 |
+
elif "location" in section or "behavior" in section:
|
| 600 |
+
# Other enum settings - return null to avoid parsing errors
|
| 601 |
+
result.append(None)
|
| 602 |
+
else:
|
| 603 |
+
# Default for other dotnet/csharp settings
|
| 604 |
+
result.append(None)
|
| 605 |
+
elif section == "tab_width" or section == "indent_size":
|
| 606 |
+
# Tab and indent settings
|
| 607 |
+
result.append(4)
|
| 608 |
+
elif section == "insert_final_newline":
|
| 609 |
+
# Editor settings
|
| 610 |
+
result.append(True)
|
| 611 |
+
else:
|
| 612 |
+
# Unknown configuration - return null
|
| 613 |
+
result.append(None)
|
| 614 |
+
|
| 615 |
+
return result
|
| 616 |
+
|
| 617 |
+
def handle_work_done_progress_create(params):
|
| 618 |
+
"""Handle work done progress create requests."""
|
| 619 |
+
# Just acknowledge the request
|
| 620 |
+
return
|
| 621 |
+
|
| 622 |
+
def handle_register_capability(params):
|
| 623 |
+
"""Handle client/registerCapability requests."""
|
| 624 |
+
# Just acknowledge the request - we don't need to track these for now
|
| 625 |
+
return
|
| 626 |
+
|
| 627 |
+
def handle_project_needs_restore(params):
|
| 628 |
+
return
|
| 629 |
+
|
| 630 |
+
# Set up notification handlers
|
| 631 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 632 |
+
self.server.on_notification("$/progress", handle_progress)
|
| 633 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 634 |
+
self.server.on_request("workspace/configuration", handle_workspace_configuration)
|
| 635 |
+
self.server.on_request("window/workDoneProgress/create", handle_work_done_progress_create)
|
| 636 |
+
self.server.on_request("client/registerCapability", handle_register_capability)
|
| 637 |
+
self.server.on_request("workspace/_roslyn_projectNeedsRestore", handle_project_needs_restore)
|
| 638 |
+
|
| 639 |
+
self.logger.log("Starting Microsoft.CodeAnalysis.LanguageServer process", logging.INFO)
|
| 640 |
+
|
| 641 |
+
try:
|
| 642 |
+
self.server.start()
|
| 643 |
+
except Exception as e:
|
| 644 |
+
self.logger.log(f"Failed to start language server process: {e}", logging.ERROR)
|
| 645 |
+
raise SolidLSPException(f"Failed to start C# language server: {e}")
|
| 646 |
+
|
| 647 |
+
# Send initialization
|
| 648 |
+
initialize_params = self._get_initialize_params()
|
| 649 |
+
|
| 650 |
+
self.logger.log("Sending initialize request to language server", logging.INFO)
|
| 651 |
+
try:
|
| 652 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 653 |
+
self.logger.log(f"Received initialize response: {init_response}", logging.DEBUG)
|
| 654 |
+
except Exception as e:
|
| 655 |
+
raise SolidLSPException(f"Failed to initialize C# language server for {self.repository_root_path}: {e}") from e
|
| 656 |
+
|
| 657 |
+
# Apply diagnostic capabilities
|
| 658 |
+
self._force_pull_diagnostics(init_response)
|
| 659 |
+
|
| 660 |
+
# Verify required capabilities
|
| 661 |
+
capabilities = init_response.get("capabilities", {})
|
| 662 |
+
required_capabilities = [
|
| 663 |
+
"textDocumentSync",
|
| 664 |
+
"definitionProvider",
|
| 665 |
+
"referencesProvider",
|
| 666 |
+
"documentSymbolProvider",
|
| 667 |
+
]
|
| 668 |
+
missing = [cap for cap in required_capabilities if cap not in capabilities]
|
| 669 |
+
if missing:
|
| 670 |
+
raise RuntimeError(
|
| 671 |
+
f"Language server is missing required capabilities: {', '.join(missing)}. "
|
| 672 |
+
"Initialization failed. Please ensure the correct version of Microsoft.CodeAnalysis.LanguageServer is installed and the .NET runtime is working."
|
| 673 |
+
)
|
| 674 |
+
|
| 675 |
+
# Complete initialization
|
| 676 |
+
self.server.notify.initialized({})
|
| 677 |
+
|
| 678 |
+
# Open solution and project files
|
| 679 |
+
self._open_solution_and_projects()
|
| 680 |
+
|
| 681 |
+
self.initialization_complete.set()
|
| 682 |
+
self.completions_available.set()
|
| 683 |
+
|
| 684 |
+
self.logger.log(
|
| 685 |
+
"Microsoft.CodeAnalysis.LanguageServer initialized and ready\n"
|
| 686 |
+
"Waiting for language server to index project files...\n"
|
| 687 |
+
"This may take a while for large projects",
|
| 688 |
+
logging.INFO,
|
| 689 |
+
)
|
| 690 |
+
|
| 691 |
+
def _force_pull_diagnostics(self, init_response: dict) -> None:
|
| 692 |
+
"""
|
| 693 |
+
Apply the diagnostic capabilities hack.
|
| 694 |
+
Forces the server to support pull diagnostics.
|
| 695 |
+
"""
|
| 696 |
+
capabilities = init_response.get("capabilities", {})
|
| 697 |
+
diagnostic_provider = capabilities.get("diagnosticProvider", {})
|
| 698 |
+
|
| 699 |
+
# Add the diagnostic capabilities hack
|
| 700 |
+
if isinstance(diagnostic_provider, dict):
|
| 701 |
+
diagnostic_provider.update(
|
| 702 |
+
{
|
| 703 |
+
"interFileDependencies": True,
|
| 704 |
+
"workDoneProgress": True,
|
| 705 |
+
"workspaceDiagnostics": True,
|
| 706 |
+
}
|
| 707 |
+
)
|
| 708 |
+
self.logger.log("Applied diagnostic capabilities hack for better C# diagnostics", logging.DEBUG)
|
| 709 |
+
|
| 710 |
+
def _open_solution_and_projects(self) -> None:
|
| 711 |
+
"""
|
| 712 |
+
Open solution and project files using notifications.
|
| 713 |
+
"""
|
| 714 |
+
# Find solution file
|
| 715 |
+
solution_file = None
|
| 716 |
+
for filename in breadth_first_file_scan(self.repository_root_path):
|
| 717 |
+
if filename.endswith(".sln"):
|
| 718 |
+
solution_file = filename
|
| 719 |
+
break
|
| 720 |
+
|
| 721 |
+
# Send solution/open notification if solution file found
|
| 722 |
+
if solution_file:
|
| 723 |
+
solution_uri = PathUtils.path_to_uri(solution_file)
|
| 724 |
+
self.server.notify.send_notification("solution/open", {"solution": solution_uri})
|
| 725 |
+
self.logger.log(f"Opened solution file: {solution_file}", logging.INFO)
|
| 726 |
+
|
| 727 |
+
# Find and open project files
|
| 728 |
+
project_files = []
|
| 729 |
+
for filename in breadth_first_file_scan(self.repository_root_path):
|
| 730 |
+
if filename.endswith(".csproj"):
|
| 731 |
+
project_files.append(filename)
|
| 732 |
+
|
| 733 |
+
# Send project/open notifications for each project file
|
| 734 |
+
if project_files:
|
| 735 |
+
project_uris = [PathUtils.path_to_uri(project_file) for project_file in project_files]
|
| 736 |
+
self.server.notify.send_notification("project/open", {"projects": project_uris})
|
| 737 |
+
self.logger.log(f"Opened project files: {project_files}", logging.DEBUG)
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import pathlib
|
| 4 |
+
|
| 5 |
+
from solidlsp.ls import SolidLanguageServer
|
| 6 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 7 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 8 |
+
from solidlsp.settings import SolidLSPSettings
|
| 9 |
+
|
| 10 |
+
from .common import RuntimeDependency, RuntimeDependencyCollection
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class DartLanguageServer(SolidLanguageServer):
|
| 14 |
+
"""
|
| 15 |
+
Provides Dart specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Dart.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
def __init__(self, config, logger, repository_root_path, solidlsp_settings: SolidLSPSettings):
|
| 19 |
+
"""
|
| 20 |
+
Creates a DartServer instance. This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 21 |
+
"""
|
| 22 |
+
executable_path = self._setup_runtime_dependencies(logger, solidlsp_settings)
|
| 23 |
+
super().__init__(
|
| 24 |
+
config,
|
| 25 |
+
logger,
|
| 26 |
+
repository_root_path,
|
| 27 |
+
ProcessLaunchInfo(cmd=executable_path, cwd=repository_root_path),
|
| 28 |
+
"dart",
|
| 29 |
+
solidlsp_settings,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
@classmethod
|
| 33 |
+
def _setup_runtime_dependencies(cls, logger: "LanguageServerLogger", solidlsp_settings: SolidLSPSettings) -> str:
|
| 34 |
+
deps = RuntimeDependencyCollection(
|
| 35 |
+
[
|
| 36 |
+
RuntimeDependency(
|
| 37 |
+
id="DartLanguageServer",
|
| 38 |
+
description="Dart Language Server for Linux (x64)",
|
| 39 |
+
url="https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-linux-x64-release.zip",
|
| 40 |
+
platform_id="linux-x64",
|
| 41 |
+
archive_type="zip",
|
| 42 |
+
binary_name="dart-sdk/bin/dart",
|
| 43 |
+
),
|
| 44 |
+
RuntimeDependency(
|
| 45 |
+
id="DartLanguageServer",
|
| 46 |
+
description="Dart Language Server for Windows (x64)",
|
| 47 |
+
url="https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-windows-x64-release.zip",
|
| 48 |
+
platform_id="win-x64",
|
| 49 |
+
archive_type="zip",
|
| 50 |
+
binary_name="dart-sdk/bin/dart.exe",
|
| 51 |
+
),
|
| 52 |
+
RuntimeDependency(
|
| 53 |
+
id="DartLanguageServer",
|
| 54 |
+
description="Dart Language Server for Windows (arm64)",
|
| 55 |
+
url="https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-windows-arm64-release.zip",
|
| 56 |
+
platform_id="win-arm64",
|
| 57 |
+
archive_type="zip",
|
| 58 |
+
binary_name="dart-sdk/bin/dart.exe",
|
| 59 |
+
),
|
| 60 |
+
RuntimeDependency(
|
| 61 |
+
id="DartLanguageServer",
|
| 62 |
+
description="Dart Language Server for macOS (x64)",
|
| 63 |
+
url="https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-macos-x64-release.zip",
|
| 64 |
+
platform_id="osx-x64",
|
| 65 |
+
archive_type="zip",
|
| 66 |
+
binary_name="dart-sdk/bin/dart",
|
| 67 |
+
),
|
| 68 |
+
RuntimeDependency(
|
| 69 |
+
id="DartLanguageServer",
|
| 70 |
+
description="Dart Language Server for macOS (arm64)",
|
| 71 |
+
url="https://storage.googleapis.com/dart-archive/channels/stable/release/3.7.1/sdk/dartsdk-macos-arm64-release.zip",
|
| 72 |
+
platform_id="osx-arm64",
|
| 73 |
+
archive_type="zip",
|
| 74 |
+
binary_name="dart-sdk/bin/dart",
|
| 75 |
+
),
|
| 76 |
+
]
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
dart_ls_dir = cls.ls_resources_dir(solidlsp_settings)
|
| 80 |
+
dart_executable_path = deps.binary_path(dart_ls_dir)
|
| 81 |
+
|
| 82 |
+
if not os.path.exists(dart_executable_path):
|
| 83 |
+
deps.install(logger, dart_ls_dir)
|
| 84 |
+
|
| 85 |
+
assert os.path.exists(dart_executable_path)
|
| 86 |
+
os.chmod(dart_executable_path, 0o755)
|
| 87 |
+
|
| 88 |
+
return f"{dart_executable_path} language-server --client-id multilspy.dart --client-version 1.2"
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def _get_initialize_params(repository_absolute_path: str):
|
| 92 |
+
"""
|
| 93 |
+
Returns the initialize params for the Dart Language Server.
|
| 94 |
+
"""
|
| 95 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 96 |
+
initialize_params = {
|
| 97 |
+
"capabilities": {},
|
| 98 |
+
"initializationOptions": {
|
| 99 |
+
"onlyAnalyzeProjectsWithOpenFiles": False,
|
| 100 |
+
"closingLabels": False,
|
| 101 |
+
"outline": False,
|
| 102 |
+
"flutterOutline": False,
|
| 103 |
+
"allowOpenUri": False,
|
| 104 |
+
},
|
| 105 |
+
"trace": "verbose",
|
| 106 |
+
"processId": os.getpid(),
|
| 107 |
+
"rootPath": repository_absolute_path,
|
| 108 |
+
"rootUri": pathlib.Path(repository_absolute_path).as_uri(),
|
| 109 |
+
"workspaceFolders": [
|
| 110 |
+
{
|
| 111 |
+
"uri": root_uri,
|
| 112 |
+
"name": os.path.basename(repository_absolute_path),
|
| 113 |
+
}
|
| 114 |
+
],
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return initialize_params
|
| 118 |
+
|
| 119 |
+
def _start_server(self):
|
| 120 |
+
"""
|
| 121 |
+
Start the language server and yield when the server is ready.
|
| 122 |
+
"""
|
| 123 |
+
|
| 124 |
+
def execute_client_command_handler(params):
|
| 125 |
+
return []
|
| 126 |
+
|
| 127 |
+
def do_nothing(params):
|
| 128 |
+
return
|
| 129 |
+
|
| 130 |
+
def check_experimental_status(params):
|
| 131 |
+
pass
|
| 132 |
+
|
| 133 |
+
def window_log_message(msg):
|
| 134 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 135 |
+
|
| 136 |
+
self.server.on_request("client/registerCapability", do_nothing)
|
| 137 |
+
self.server.on_notification("language/status", do_nothing)
|
| 138 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 139 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 140 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 141 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 142 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 143 |
+
self.server.on_notification("experimental/serverStatus", check_experimental_status)
|
| 144 |
+
|
| 145 |
+
self.logger.log("Starting dart-language-server server process", logging.INFO)
|
| 146 |
+
self.server.start()
|
| 147 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 148 |
+
self.logger.log(
|
| 149 |
+
"Sending initialize request to dart-language-server",
|
| 150 |
+
logging.DEBUG,
|
| 151 |
+
)
|
| 152 |
+
init_response = self.server.send_request("initialize", initialize_params)
|
| 153 |
+
self.logger.log(
|
| 154 |
+
f"Received initialize response from dart-language-server: {init_response}",
|
| 155 |
+
logging.INFO,
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
self.server.notify.initialized({})
|
projects/ui/serena-new/src/solidlsp/language_servers/eclipse_jdtls.py
ADDED
|
@@ -0,0 +1,723 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
"""
|
| 2 |
+
Provides Java specific instantiation of the LanguageServer class. Contains various configurations and settings specific to Java.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import dataclasses
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
import pathlib
|
| 9 |
+
import shutil
|
| 10 |
+
import threading
|
| 11 |
+
import uuid
|
| 12 |
+
from pathlib import PurePath
|
| 13 |
+
|
| 14 |
+
from overrides import override
|
| 15 |
+
|
| 16 |
+
from solidlsp.ls import SolidLanguageServer
|
| 17 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 18 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 19 |
+
from solidlsp.ls_utils import FileUtils, PlatformUtils
|
| 20 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 21 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 22 |
+
from solidlsp.settings import SolidLSPSettings
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@dataclasses.dataclass
|
| 26 |
+
class RuntimeDependencyPaths:
|
| 27 |
+
"""
|
| 28 |
+
Stores the paths to the runtime dependencies of EclipseJDTLS
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
gradle_path: str
|
| 32 |
+
lombok_jar_path: str
|
| 33 |
+
jre_path: str
|
| 34 |
+
jre_home_path: str
|
| 35 |
+
jdtls_launcher_jar_path: str
|
| 36 |
+
jdtls_readonly_config_path: str
|
| 37 |
+
intellicode_jar_path: str
|
| 38 |
+
intellisense_members_path: str
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class EclipseJDTLS(SolidLanguageServer):
|
| 42 |
+
"""
|
| 43 |
+
The EclipseJDTLS class provides a Java specific implementation of the LanguageServer class
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
def __init__(
|
| 47 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 48 |
+
):
|
| 49 |
+
"""
|
| 50 |
+
Creates a new EclipseJDTLS instance initializing the language server settings appropriately.
|
| 51 |
+
This class is not meant to be instantiated directly. Use LanguageServer.create() instead.
|
| 52 |
+
"""
|
| 53 |
+
runtime_dependency_paths = self._setupRuntimeDependencies(logger, config, solidlsp_settings)
|
| 54 |
+
self.runtime_dependency_paths = runtime_dependency_paths
|
| 55 |
+
|
| 56 |
+
# ws_dir is the workspace directory for the EclipseJDTLS server
|
| 57 |
+
ws_dir = str(
|
| 58 |
+
PurePath(
|
| 59 |
+
solidlsp_settings.ls_resources_dir,
|
| 60 |
+
"EclipseJDTLS",
|
| 61 |
+
"workspaces",
|
| 62 |
+
uuid.uuid4().hex,
|
| 63 |
+
)
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# shared_cache_location is the global cache used by Eclipse JDTLS across all workspaces
|
| 67 |
+
shared_cache_location = str(PurePath(solidlsp_settings.ls_resources_dir, "lsp", "EclipseJDTLS", "sharedIndex"))
|
| 68 |
+
os.makedirs(shared_cache_location, exist_ok=True)
|
| 69 |
+
os.makedirs(ws_dir, exist_ok=True)
|
| 70 |
+
|
| 71 |
+
jre_path = self.runtime_dependency_paths.jre_path
|
| 72 |
+
lombok_jar_path = self.runtime_dependency_paths.lombok_jar_path
|
| 73 |
+
|
| 74 |
+
jdtls_launcher_jar = self.runtime_dependency_paths.jdtls_launcher_jar_path
|
| 75 |
+
|
| 76 |
+
data_dir = str(PurePath(ws_dir, "data_dir"))
|
| 77 |
+
jdtls_config_path = str(PurePath(ws_dir, "config_path"))
|
| 78 |
+
|
| 79 |
+
jdtls_readonly_config_path = self.runtime_dependency_paths.jdtls_readonly_config_path
|
| 80 |
+
|
| 81 |
+
if not os.path.exists(jdtls_config_path):
|
| 82 |
+
shutil.copytree(jdtls_readonly_config_path, jdtls_config_path)
|
| 83 |
+
|
| 84 |
+
for static_path in [
|
| 85 |
+
jre_path,
|
| 86 |
+
lombok_jar_path,
|
| 87 |
+
jdtls_launcher_jar,
|
| 88 |
+
jdtls_config_path,
|
| 89 |
+
jdtls_readonly_config_path,
|
| 90 |
+
]:
|
| 91 |
+
assert os.path.exists(static_path), static_path
|
| 92 |
+
|
| 93 |
+
# TODO: Add "self.runtime_dependency_paths.jre_home_path"/bin to $PATH as well
|
| 94 |
+
proc_env = {"syntaxserver": "false", "JAVA_HOME": self.runtime_dependency_paths.jre_home_path}
|
| 95 |
+
proc_cwd = repository_root_path
|
| 96 |
+
cmd = " ".join(
|
| 97 |
+
[
|
| 98 |
+
jre_path,
|
| 99 |
+
"--add-modules=ALL-SYSTEM",
|
| 100 |
+
"--add-opens",
|
| 101 |
+
"java.base/java.util=ALL-UNNAMED",
|
| 102 |
+
"--add-opens",
|
| 103 |
+
"java.base/java.lang=ALL-UNNAMED",
|
| 104 |
+
"--add-opens",
|
| 105 |
+
"java.base/sun.nio.fs=ALL-UNNAMED",
|
| 106 |
+
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
| 107 |
+
"-Dosgi.bundles.defaultStartLevel=4",
|
| 108 |
+
"-Declipse.product=org.eclipse.jdt.ls.core.product",
|
| 109 |
+
"-Djava.import.generatesMetadataFilesAtProjectRoot=false",
|
| 110 |
+
"-Dfile.encoding=utf8",
|
| 111 |
+
"-noverify",
|
| 112 |
+
"-XX:+UseParallelGC",
|
| 113 |
+
"-XX:GCTimeRatio=4",
|
| 114 |
+
"-XX:AdaptiveSizePolicyWeight=90",
|
| 115 |
+
"-Dsun.zip.disableMemoryMapping=true",
|
| 116 |
+
"-Djava.lsp.joinOnCompletion=true",
|
| 117 |
+
"-Xmx3G",
|
| 118 |
+
"-Xms100m",
|
| 119 |
+
"-Xlog:disable",
|
| 120 |
+
"-Dlog.level=ALL",
|
| 121 |
+
f'"-javaagent:{lombok_jar_path}"',
|
| 122 |
+
f'"-Djdt.core.sharedIndexLocation={shared_cache_location}"',
|
| 123 |
+
"-jar",
|
| 124 |
+
f'"{jdtls_launcher_jar}"',
|
| 125 |
+
"-configuration",
|
| 126 |
+
f'"{jdtls_config_path}"',
|
| 127 |
+
"-data",
|
| 128 |
+
f'"{data_dir}"',
|
| 129 |
+
]
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
self.service_ready_event = threading.Event()
|
| 133 |
+
self.intellicode_enable_command_available = threading.Event()
|
| 134 |
+
self.initialize_searcher_command_available = threading.Event()
|
| 135 |
+
|
| 136 |
+
super().__init__(
|
| 137 |
+
config, logger, repository_root_path, ProcessLaunchInfo(cmd, proc_env, proc_cwd), "java", solidlsp_settings=solidlsp_settings
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
@override
|
| 141 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 142 |
+
# Ignore common Java build directories from different build tools:
|
| 143 |
+
# - Maven: target
|
| 144 |
+
# - Gradle: build, .gradle
|
| 145 |
+
# - Eclipse: bin, .settings
|
| 146 |
+
# - IntelliJ IDEA: out, .idea
|
| 147 |
+
# - General: classes, dist, lib
|
| 148 |
+
return super().is_ignored_dirname(dirname) or dirname in [
|
| 149 |
+
"target", # Maven
|
| 150 |
+
"build", # Gradle
|
| 151 |
+
"bin", # Eclipse
|
| 152 |
+
"out", # IntelliJ IDEA
|
| 153 |
+
"classes", # General
|
| 154 |
+
"dist", # General
|
| 155 |
+
"lib", # General
|
| 156 |
+
]
|
| 157 |
+
|
| 158 |
+
@classmethod
|
| 159 |
+
def _setupRuntimeDependencies(
|
| 160 |
+
cls, logger: LanguageServerLogger, config: LanguageServerConfig, solidlsp_settings: SolidLSPSettings
|
| 161 |
+
) -> RuntimeDependencyPaths:
|
| 162 |
+
"""
|
| 163 |
+
Setup runtime dependencies for EclipseJDTLS and return the paths.
|
| 164 |
+
"""
|
| 165 |
+
platformId = PlatformUtils.get_platform_id()
|
| 166 |
+
|
| 167 |
+
runtime_dependencies = {
|
| 168 |
+
"gradle": {
|
| 169 |
+
"platform-agnostic": {
|
| 170 |
+
"url": "https://services.gradle.org/distributions/gradle-8.14.2-bin.zip",
|
| 171 |
+
"archiveType": "zip",
|
| 172 |
+
"relative_extraction_path": ".",
|
| 173 |
+
}
|
| 174 |
+
},
|
| 175 |
+
"vscode-java": {
|
| 176 |
+
"darwin-arm64": {
|
| 177 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-arm64-1.42.0-561.vsix",
|
| 178 |
+
"archiveType": "zip",
|
| 179 |
+
"relative_extraction_path": "vscode-java",
|
| 180 |
+
},
|
| 181 |
+
"osx-arm64": {
|
| 182 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-arm64-1.42.0-561.vsix",
|
| 183 |
+
"archiveType": "zip",
|
| 184 |
+
"relative_extraction_path": "vscode-java",
|
| 185 |
+
"jre_home_path": "extension/jre/21.0.7-macosx-aarch64",
|
| 186 |
+
"jre_path": "extension/jre/21.0.7-macosx-aarch64/bin/java",
|
| 187 |
+
"lombok_jar_path": "extension/lombok/lombok-1.18.36.jar",
|
| 188 |
+
"jdtls_launcher_jar_path": "extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar",
|
| 189 |
+
"jdtls_readonly_config_path": "extension/server/config_mac_arm",
|
| 190 |
+
},
|
| 191 |
+
"osx-x64": {
|
| 192 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-darwin-x64-1.42.0-561.vsix",
|
| 193 |
+
"archiveType": "zip",
|
| 194 |
+
"relative_extraction_path": "vscode-java",
|
| 195 |
+
"jre_home_path": "extension/jre/21.0.7-macosx-x86_64",
|
| 196 |
+
"jre_path": "extension/jre/21.0.7-macosx-x86_64/bin/java",
|
| 197 |
+
"lombok_jar_path": "extension/lombok/lombok-1.18.36.jar",
|
| 198 |
+
"jdtls_launcher_jar_path": "extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar",
|
| 199 |
+
"jdtls_readonly_config_path": "extension/server/config_mac",
|
| 200 |
+
},
|
| 201 |
+
"linux-arm64": {
|
| 202 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-arm64-1.42.0-561.vsix",
|
| 203 |
+
"archiveType": "zip",
|
| 204 |
+
"relative_extraction_path": "vscode-java",
|
| 205 |
+
},
|
| 206 |
+
"linux-x64": {
|
| 207 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-linux-x64-1.42.0-561.vsix",
|
| 208 |
+
"archiveType": "zip",
|
| 209 |
+
"relative_extraction_path": "vscode-java",
|
| 210 |
+
"jre_home_path": "extension/jre/21.0.7-linux-x86_64",
|
| 211 |
+
"jre_path": "extension/jre/21.0.7-linux-x86_64/bin/java",
|
| 212 |
+
"lombok_jar_path": "extension/lombok/lombok-1.18.36.jar",
|
| 213 |
+
"jdtls_launcher_jar_path": "extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar",
|
| 214 |
+
"jdtls_readonly_config_path": "extension/server/config_linux",
|
| 215 |
+
},
|
| 216 |
+
"win-x64": {
|
| 217 |
+
"url": "https://github.com/redhat-developer/vscode-java/releases/download/v1.42.0/java-win32-x64-1.42.0-561.vsix",
|
| 218 |
+
"archiveType": "zip",
|
| 219 |
+
"relative_extraction_path": "vscode-java",
|
| 220 |
+
"jre_home_path": "extension/jre/21.0.7-win32-x86_64",
|
| 221 |
+
"jre_path": "extension/jre/21.0.7-win32-x86_64/bin/java.exe",
|
| 222 |
+
"lombok_jar_path": "extension/lombok/lombok-1.18.36.jar",
|
| 223 |
+
"jdtls_launcher_jar_path": "extension/server/plugins/org.eclipse.equinox.launcher_1.7.0.v20250424-1814.jar",
|
| 224 |
+
"jdtls_readonly_config_path": "extension/server/config_win",
|
| 225 |
+
},
|
| 226 |
+
},
|
| 227 |
+
"intellicode": {
|
| 228 |
+
"platform-agnostic": {
|
| 229 |
+
"url": "https://VisualStudioExptTeam.gallery.vsassets.io/_apis/public/gallery/publisher/VisualStudioExptTeam/extension/vscodeintellicode/1.2.30/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage",
|
| 230 |
+
"alternate_url": "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/VisualStudioExptTeam/vsextensions/vscodeintellicode/1.2.30/vspackage",
|
| 231 |
+
"archiveType": "zip",
|
| 232 |
+
"relative_extraction_path": "intellicode",
|
| 233 |
+
"intellicode_jar_path": "extension/dist/com.microsoft.jdtls.intellicode.core-0.7.0.jar",
|
| 234 |
+
"intellisense_members_path": "extension/dist/bundledModels/java_intellisense-members",
|
| 235 |
+
}
|
| 236 |
+
},
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
# assert platformId.value in [
|
| 240 |
+
# "linux-x64",
|
| 241 |
+
# "win-x64",
|
| 242 |
+
# ], "Only linux-x64 platform is supported for in multilspy at the moment"
|
| 243 |
+
|
| 244 |
+
gradle_path = str(
|
| 245 |
+
PurePath(
|
| 246 |
+
cls.ls_resources_dir(solidlsp_settings),
|
| 247 |
+
"gradle-8.14.2",
|
| 248 |
+
)
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
if not os.path.exists(gradle_path):
|
| 252 |
+
FileUtils.download_and_extract_archive(
|
| 253 |
+
logger,
|
| 254 |
+
runtime_dependencies["gradle"]["platform-agnostic"]["url"],
|
| 255 |
+
str(PurePath(gradle_path).parent),
|
| 256 |
+
runtime_dependencies["gradle"]["platform-agnostic"]["archiveType"],
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
assert os.path.exists(gradle_path)
|
| 260 |
+
|
| 261 |
+
dependency = runtime_dependencies["vscode-java"][platformId.value]
|
| 262 |
+
vscode_java_path = str(PurePath(cls.ls_resources_dir(solidlsp_settings), dependency["relative_extraction_path"]))
|
| 263 |
+
os.makedirs(vscode_java_path, exist_ok=True)
|
| 264 |
+
jre_home_path = str(PurePath(vscode_java_path, dependency["jre_home_path"]))
|
| 265 |
+
jre_path = str(PurePath(vscode_java_path, dependency["jre_path"]))
|
| 266 |
+
lombok_jar_path = str(PurePath(vscode_java_path, dependency["lombok_jar_path"]))
|
| 267 |
+
jdtls_launcher_jar_path = str(PurePath(vscode_java_path, dependency["jdtls_launcher_jar_path"]))
|
| 268 |
+
jdtls_readonly_config_path = str(PurePath(vscode_java_path, dependency["jdtls_readonly_config_path"]))
|
| 269 |
+
if not all(
|
| 270 |
+
[
|
| 271 |
+
os.path.exists(vscode_java_path),
|
| 272 |
+
os.path.exists(jre_home_path),
|
| 273 |
+
os.path.exists(jre_path),
|
| 274 |
+
os.path.exists(lombok_jar_path),
|
| 275 |
+
os.path.exists(jdtls_launcher_jar_path),
|
| 276 |
+
os.path.exists(jdtls_readonly_config_path),
|
| 277 |
+
]
|
| 278 |
+
):
|
| 279 |
+
FileUtils.download_and_extract_archive(logger, dependency["url"], vscode_java_path, dependency["archiveType"])
|
| 280 |
+
|
| 281 |
+
os.chmod(jre_path, 0o755)
|
| 282 |
+
|
| 283 |
+
assert os.path.exists(vscode_java_path)
|
| 284 |
+
assert os.path.exists(jre_home_path)
|
| 285 |
+
assert os.path.exists(jre_path)
|
| 286 |
+
assert os.path.exists(lombok_jar_path)
|
| 287 |
+
assert os.path.exists(jdtls_launcher_jar_path)
|
| 288 |
+
assert os.path.exists(jdtls_readonly_config_path)
|
| 289 |
+
|
| 290 |
+
dependency = runtime_dependencies["intellicode"]["platform-agnostic"]
|
| 291 |
+
intellicode_directory_path = str(PurePath(cls.ls_resources_dir(solidlsp_settings), dependency["relative_extraction_path"]))
|
| 292 |
+
os.makedirs(intellicode_directory_path, exist_ok=True)
|
| 293 |
+
intellicode_jar_path = str(PurePath(intellicode_directory_path, dependency["intellicode_jar_path"]))
|
| 294 |
+
intellisense_members_path = str(PurePath(intellicode_directory_path, dependency["intellisense_members_path"]))
|
| 295 |
+
if not all(
|
| 296 |
+
[
|
| 297 |
+
os.path.exists(intellicode_directory_path),
|
| 298 |
+
os.path.exists(intellicode_jar_path),
|
| 299 |
+
os.path.exists(intellisense_members_path),
|
| 300 |
+
]
|
| 301 |
+
):
|
| 302 |
+
FileUtils.download_and_extract_archive(logger, dependency["url"], intellicode_directory_path, dependency["archiveType"])
|
| 303 |
+
|
| 304 |
+
assert os.path.exists(intellicode_directory_path)
|
| 305 |
+
assert os.path.exists(intellicode_jar_path)
|
| 306 |
+
assert os.path.exists(intellisense_members_path)
|
| 307 |
+
|
| 308 |
+
return RuntimeDependencyPaths(
|
| 309 |
+
gradle_path=gradle_path,
|
| 310 |
+
lombok_jar_path=lombok_jar_path,
|
| 311 |
+
jre_path=jre_path,
|
| 312 |
+
jre_home_path=jre_home_path,
|
| 313 |
+
jdtls_launcher_jar_path=jdtls_launcher_jar_path,
|
| 314 |
+
jdtls_readonly_config_path=jdtls_readonly_config_path,
|
| 315 |
+
intellicode_jar_path=intellicode_jar_path,
|
| 316 |
+
intellisense_members_path=intellisense_members_path,
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
def _get_initialize_params(self, repository_absolute_path: str) -> InitializeParams:
|
| 320 |
+
"""
|
| 321 |
+
Returns the initialize parameters for the EclipseJDTLS server.
|
| 322 |
+
"""
|
| 323 |
+
# Look into https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/Preferences.java to understand all the options available
|
| 324 |
+
|
| 325 |
+
if not os.path.isabs(repository_absolute_path):
|
| 326 |
+
repository_absolute_path = os.path.abspath(repository_absolute_path)
|
| 327 |
+
repo_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 328 |
+
|
| 329 |
+
initialize_params = {
|
| 330 |
+
"locale": "en",
|
| 331 |
+
"rootPath": repository_absolute_path,
|
| 332 |
+
"rootUri": pathlib.Path(repository_absolute_path).as_uri(),
|
| 333 |
+
"capabilities": {
|
| 334 |
+
"workspace": {
|
| 335 |
+
"applyEdit": True,
|
| 336 |
+
"workspaceEdit": {
|
| 337 |
+
"documentChanges": True,
|
| 338 |
+
"resourceOperations": ["create", "rename", "delete"],
|
| 339 |
+
"failureHandling": "textOnlyTransactional",
|
| 340 |
+
"normalizesLineEndings": True,
|
| 341 |
+
"changeAnnotationSupport": {"groupsOnLabel": True},
|
| 342 |
+
},
|
| 343 |
+
"didChangeConfiguration": {"dynamicRegistration": True},
|
| 344 |
+
"didChangeWatchedFiles": {"dynamicRegistration": True, "relativePatternSupport": True},
|
| 345 |
+
"symbol": {
|
| 346 |
+
"dynamicRegistration": True,
|
| 347 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 348 |
+
"tagSupport": {"valueSet": [1]},
|
| 349 |
+
"resolveSupport": {"properties": ["location.range"]},
|
| 350 |
+
},
|
| 351 |
+
"codeLens": {"refreshSupport": True},
|
| 352 |
+
"executeCommand": {"dynamicRegistration": True},
|
| 353 |
+
"configuration": True,
|
| 354 |
+
"workspaceFolders": True,
|
| 355 |
+
"semanticTokens": {"refreshSupport": True},
|
| 356 |
+
"fileOperations": {
|
| 357 |
+
"dynamicRegistration": True,
|
| 358 |
+
"didCreate": True,
|
| 359 |
+
"didRename": True,
|
| 360 |
+
"didDelete": True,
|
| 361 |
+
"willCreate": True,
|
| 362 |
+
"willRename": True,
|
| 363 |
+
"willDelete": True,
|
| 364 |
+
},
|
| 365 |
+
"inlineValue": {"refreshSupport": True},
|
| 366 |
+
"inlayHint": {"refreshSupport": True},
|
| 367 |
+
"diagnostics": {"refreshSupport": True},
|
| 368 |
+
},
|
| 369 |
+
"textDocument": {
|
| 370 |
+
"publishDiagnostics": {
|
| 371 |
+
"relatedInformation": True,
|
| 372 |
+
"versionSupport": False,
|
| 373 |
+
"tagSupport": {"valueSet": [1, 2]},
|
| 374 |
+
"codeDescriptionSupport": True,
|
| 375 |
+
"dataSupport": True,
|
| 376 |
+
},
|
| 377 |
+
"synchronization": {"dynamicRegistration": True, "willSave": True, "willSaveWaitUntil": True, "didSave": True},
|
| 378 |
+
# TODO: we have an assert that completion provider is not included in the capabilities at server startup
|
| 379 |
+
# Removing this will cause the assert to fail. Investigate why this is the case, simplify config
|
| 380 |
+
"completion": {
|
| 381 |
+
"dynamicRegistration": True,
|
| 382 |
+
"contextSupport": True,
|
| 383 |
+
"completionItem": {
|
| 384 |
+
"snippetSupport": False,
|
| 385 |
+
"commitCharactersSupport": True,
|
| 386 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 387 |
+
"deprecatedSupport": True,
|
| 388 |
+
"preselectSupport": True,
|
| 389 |
+
"tagSupport": {"valueSet": [1]},
|
| 390 |
+
"insertReplaceSupport": False,
|
| 391 |
+
"resolveSupport": {"properties": ["documentation", "detail", "additionalTextEdits"]},
|
| 392 |
+
"insertTextModeSupport": {"valueSet": [1, 2]},
|
| 393 |
+
"labelDetailsSupport": True,
|
| 394 |
+
},
|
| 395 |
+
"insertTextMode": 2,
|
| 396 |
+
"completionItemKind": {
|
| 397 |
+
"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
|
| 398 |
+
},
|
| 399 |
+
"completionList": {"itemDefaults": ["commitCharacters", "editRange", "insertTextFormat", "insertTextMode"]},
|
| 400 |
+
},
|
| 401 |
+
"hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]},
|
| 402 |
+
"signatureHelp": {
|
| 403 |
+
"dynamicRegistration": True,
|
| 404 |
+
"signatureInformation": {
|
| 405 |
+
"documentationFormat": ["markdown", "plaintext"],
|
| 406 |
+
"parameterInformation": {"labelOffsetSupport": True},
|
| 407 |
+
"activeParameterSupport": True,
|
| 408 |
+
},
|
| 409 |
+
},
|
| 410 |
+
"definition": {"dynamicRegistration": True, "linkSupport": True},
|
| 411 |
+
"references": {"dynamicRegistration": True},
|
| 412 |
+
"documentSymbol": {
|
| 413 |
+
"dynamicRegistration": True,
|
| 414 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 415 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 416 |
+
"tagSupport": {"valueSet": [1]},
|
| 417 |
+
"labelSupport": True,
|
| 418 |
+
},
|
| 419 |
+
"rename": {
|
| 420 |
+
"dynamicRegistration": True,
|
| 421 |
+
"prepareSupport": True,
|
| 422 |
+
"prepareSupportDefaultBehavior": 1,
|
| 423 |
+
"honorsChangeAnnotations": True,
|
| 424 |
+
},
|
| 425 |
+
"documentLink": {"dynamicRegistration": True, "tooltipSupport": True},
|
| 426 |
+
"typeDefinition": {"dynamicRegistration": True, "linkSupport": True},
|
| 427 |
+
"implementation": {"dynamicRegistration": True, "linkSupport": True},
|
| 428 |
+
"colorProvider": {"dynamicRegistration": True},
|
| 429 |
+
"declaration": {"dynamicRegistration": True, "linkSupport": True},
|
| 430 |
+
"selectionRange": {"dynamicRegistration": True},
|
| 431 |
+
"callHierarchy": {"dynamicRegistration": True},
|
| 432 |
+
"semanticTokens": {
|
| 433 |
+
"dynamicRegistration": True,
|
| 434 |
+
"tokenTypes": [
|
| 435 |
+
"namespace",
|
| 436 |
+
"type",
|
| 437 |
+
"class",
|
| 438 |
+
"enum",
|
| 439 |
+
"interface",
|
| 440 |
+
"struct",
|
| 441 |
+
"typeParameter",
|
| 442 |
+
"parameter",
|
| 443 |
+
"variable",
|
| 444 |
+
"property",
|
| 445 |
+
"enumMember",
|
| 446 |
+
"event",
|
| 447 |
+
"function",
|
| 448 |
+
"method",
|
| 449 |
+
"macro",
|
| 450 |
+
"keyword",
|
| 451 |
+
"modifier",
|
| 452 |
+
"comment",
|
| 453 |
+
"string",
|
| 454 |
+
"number",
|
| 455 |
+
"regexp",
|
| 456 |
+
"operator",
|
| 457 |
+
"decorator",
|
| 458 |
+
],
|
| 459 |
+
"tokenModifiers": [
|
| 460 |
+
"declaration",
|
| 461 |
+
"definition",
|
| 462 |
+
"readonly",
|
| 463 |
+
"static",
|
| 464 |
+
"deprecated",
|
| 465 |
+
"abstract",
|
| 466 |
+
"async",
|
| 467 |
+
"modification",
|
| 468 |
+
"documentation",
|
| 469 |
+
"defaultLibrary",
|
| 470 |
+
],
|
| 471 |
+
"formats": ["relative"],
|
| 472 |
+
"requests": {"range": True, "full": {"delta": True}},
|
| 473 |
+
"multilineTokenSupport": False,
|
| 474 |
+
"overlappingTokenSupport": False,
|
| 475 |
+
"serverCancelSupport": True,
|
| 476 |
+
"augmentsSyntaxTokens": True,
|
| 477 |
+
},
|
| 478 |
+
"typeHierarchy": {"dynamicRegistration": True},
|
| 479 |
+
"inlineValue": {"dynamicRegistration": True},
|
| 480 |
+
"diagnostic": {"dynamicRegistration": True, "relatedDocumentSupport": False},
|
| 481 |
+
},
|
| 482 |
+
"general": {
|
| 483 |
+
"staleRequestSupport": {
|
| 484 |
+
"cancel": True,
|
| 485 |
+
"retryOnContentModified": [
|
| 486 |
+
"textDocument/semanticTokens/full",
|
| 487 |
+
"textDocument/semanticTokens/range",
|
| 488 |
+
"textDocument/semanticTokens/full/delta",
|
| 489 |
+
],
|
| 490 |
+
},
|
| 491 |
+
"regularExpressions": {"engine": "ECMAScript", "version": "ES2020"},
|
| 492 |
+
"positionEncodings": ["utf-16"],
|
| 493 |
+
},
|
| 494 |
+
"notebookDocument": {"synchronization": {"dynamicRegistration": True, "executionSummarySupport": True}},
|
| 495 |
+
},
|
| 496 |
+
"initializationOptions": {
|
| 497 |
+
"bundles": ["intellicode-core.jar"],
|
| 498 |
+
"settings": {
|
| 499 |
+
"java": {
|
| 500 |
+
"home": None,
|
| 501 |
+
"jdt": {
|
| 502 |
+
"ls": {
|
| 503 |
+
"java": {"home": None},
|
| 504 |
+
"vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -Xlog:disable",
|
| 505 |
+
"lombokSupport": {"enabled": True},
|
| 506 |
+
"protobufSupport": {"enabled": True},
|
| 507 |
+
"androidSupport": {"enabled": True},
|
| 508 |
+
}
|
| 509 |
+
},
|
| 510 |
+
"errors": {"incompleteClasspath": {"severity": "error"}},
|
| 511 |
+
"configuration": {
|
| 512 |
+
"checkProjectSettingsExclusions": False,
|
| 513 |
+
"updateBuildConfiguration": "interactive",
|
| 514 |
+
"maven": {
|
| 515 |
+
"userSettings": None,
|
| 516 |
+
"globalSettings": None,
|
| 517 |
+
"notCoveredPluginExecutionSeverity": "warning",
|
| 518 |
+
"defaultMojoExecutionAction": "ignore",
|
| 519 |
+
},
|
| 520 |
+
"workspaceCacheLimit": 90,
|
| 521 |
+
"runtimes": [
|
| 522 |
+
{"name": "JavaSE-21", "path": "static/vscode-java/extension/jre/21.0.7-linux-x86_64", "default": True}
|
| 523 |
+
],
|
| 524 |
+
},
|
| 525 |
+
"trace": {"server": "verbose"},
|
| 526 |
+
"import": {
|
| 527 |
+
"maven": {
|
| 528 |
+
"enabled": True,
|
| 529 |
+
"offline": {"enabled": False},
|
| 530 |
+
"disableTestClasspathFlag": False,
|
| 531 |
+
},
|
| 532 |
+
"gradle": {
|
| 533 |
+
"enabled": True,
|
| 534 |
+
"wrapper": {"enabled": False},
|
| 535 |
+
"version": None,
|
| 536 |
+
"home": "abs(static/gradle-7.3.3)",
|
| 537 |
+
"java": {"home": "abs(static/launch_jres/21.0.7-linux-x86_64)"},
|
| 538 |
+
"offline": {"enabled": False},
|
| 539 |
+
"arguments": None,
|
| 540 |
+
"jvmArguments": None,
|
| 541 |
+
"user": {"home": None},
|
| 542 |
+
"annotationProcessing": {"enabled": True},
|
| 543 |
+
},
|
| 544 |
+
"exclusions": [
|
| 545 |
+
"**/node_modules/**",
|
| 546 |
+
"**/.metadata/**",
|
| 547 |
+
"**/archetype-resources/**",
|
| 548 |
+
"**/META-INF/maven/**",
|
| 549 |
+
],
|
| 550 |
+
"generatesMetadataFilesAtProjectRoot": False,
|
| 551 |
+
},
|
| 552 |
+
"maven": {"downloadSources": True, "updateSnapshots": True},
|
| 553 |
+
"eclipse": {"downloadSources": True},
|
| 554 |
+
"signatureHelp": {"enabled": True, "description": {"enabled": True}},
|
| 555 |
+
"implementationsCodeLens": {"enabled": True},
|
| 556 |
+
"format": {
|
| 557 |
+
"enabled": True,
|
| 558 |
+
"settings": {"url": None, "profile": None},
|
| 559 |
+
"comments": {"enabled": True},
|
| 560 |
+
"onType": {"enabled": True},
|
| 561 |
+
"insertSpaces": True,
|
| 562 |
+
"tabSize": 4,
|
| 563 |
+
},
|
| 564 |
+
"saveActions": {"organizeImports": False},
|
| 565 |
+
"project": {
|
| 566 |
+
"referencedLibraries": ["lib/**/*.jar"],
|
| 567 |
+
"importOnFirstTimeStartup": "automatic",
|
| 568 |
+
"importHint": True,
|
| 569 |
+
"resourceFilters": ["node_modules", "\\.git"],
|
| 570 |
+
"encoding": "ignore",
|
| 571 |
+
"exportJar": {"targetPath": "${workspaceFolder}/${workspaceFolderBasename}.jar"},
|
| 572 |
+
},
|
| 573 |
+
"contentProvider": {"preferred": None},
|
| 574 |
+
"autobuild": {"enabled": True},
|
| 575 |
+
"maxConcurrentBuilds": 1,
|
| 576 |
+
"selectionRange": {"enabled": True},
|
| 577 |
+
"showBuildStatusOnStart": {"enabled": "notification"},
|
| 578 |
+
"server": {"launchMode": "Standard"},
|
| 579 |
+
"sources": {"organizeImports": {"starThreshold": 99, "staticStarThreshold": 99}},
|
| 580 |
+
"imports": {"gradle": {"wrapper": {"checksums": []}}},
|
| 581 |
+
"templates": {"fileHeader": [], "typeComment": []},
|
| 582 |
+
"references": {"includeAccessors": True, "includeDecompiledSources": True},
|
| 583 |
+
"typeHierarchy": {"lazyLoad": False},
|
| 584 |
+
"settings": {"url": None},
|
| 585 |
+
"symbols": {"includeSourceMethodDeclarations": False},
|
| 586 |
+
"inlayHints": {"parameterNames": {"enabled": "literals", "exclusions": []}},
|
| 587 |
+
"codeAction": {"sortMembers": {"avoidVolatileChanges": True}},
|
| 588 |
+
"compile": {
|
| 589 |
+
"nullAnalysis": {
|
| 590 |
+
"nonnull": [
|
| 591 |
+
"javax.annotation.Nonnull",
|
| 592 |
+
"org.eclipse.jdt.annotation.NonNull",
|
| 593 |
+
"org.springframework.lang.NonNull",
|
| 594 |
+
],
|
| 595 |
+
"nullable": [
|
| 596 |
+
"javax.annotation.Nullable",
|
| 597 |
+
"org.eclipse.jdt.annotation.Nullable",
|
| 598 |
+
"org.springframework.lang.Nullable",
|
| 599 |
+
],
|
| 600 |
+
"mode": "automatic",
|
| 601 |
+
}
|
| 602 |
+
},
|
| 603 |
+
"sharedIndexes": {"enabled": "auto", "location": ""},
|
| 604 |
+
"silentNotification": False,
|
| 605 |
+
"dependency": {
|
| 606 |
+
"showMembers": False,
|
| 607 |
+
"syncWithFolderExplorer": True,
|
| 608 |
+
"autoRefresh": True,
|
| 609 |
+
"refreshDelay": 2000,
|
| 610 |
+
"packagePresentation": "flat",
|
| 611 |
+
},
|
| 612 |
+
"help": {"firstView": "auto", "showReleaseNotes": True, "collectErrorLog": False},
|
| 613 |
+
"test": {"defaultConfig": "", "config": {}},
|
| 614 |
+
}
|
| 615 |
+
},
|
| 616 |
+
},
|
| 617 |
+
"trace": "verbose",
|
| 618 |
+
"processId": os.getpid(),
|
| 619 |
+
"workspaceFolders": [
|
| 620 |
+
{
|
| 621 |
+
"uri": repo_uri,
|
| 622 |
+
"name": os.path.basename(repository_absolute_path),
|
| 623 |
+
}
|
| 624 |
+
],
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
initialize_params["initializationOptions"]["workspaceFolders"] = [repo_uri]
|
| 628 |
+
bundles = [self.runtime_dependency_paths.intellicode_jar_path]
|
| 629 |
+
initialize_params["initializationOptions"]["bundles"] = bundles
|
| 630 |
+
initialize_params["initializationOptions"]["settings"]["java"]["configuration"]["runtimes"] = [
|
| 631 |
+
{"name": "JavaSE-21", "path": self.runtime_dependency_paths.jre_home_path, "default": True}
|
| 632 |
+
]
|
| 633 |
+
|
| 634 |
+
for runtime in initialize_params["initializationOptions"]["settings"]["java"]["configuration"]["runtimes"]:
|
| 635 |
+
assert "name" in runtime
|
| 636 |
+
assert "path" in runtime
|
| 637 |
+
assert os.path.exists(runtime["path"]), f"Runtime required for eclipse_jdtls at path {runtime['path']} does not exist"
|
| 638 |
+
|
| 639 |
+
gradle_settings = initialize_params["initializationOptions"]["settings"]["java"]["import"]["gradle"]
|
| 640 |
+
gradle_settings["home"] = self.runtime_dependency_paths.gradle_path
|
| 641 |
+
gradle_settings["java"]["home"] = self.runtime_dependency_paths.jre_path
|
| 642 |
+
return initialize_params
|
| 643 |
+
|
| 644 |
+
def _start_server(self):
|
| 645 |
+
"""
|
| 646 |
+
Starts the Eclipse JDTLS Language Server
|
| 647 |
+
"""
|
| 648 |
+
|
| 649 |
+
def register_capability_handler(params):
|
| 650 |
+
assert "registrations" in params
|
| 651 |
+
for registration in params["registrations"]:
|
| 652 |
+
if registration["method"] == "textDocument/completion":
|
| 653 |
+
assert registration["registerOptions"]["resolveProvider"] == True
|
| 654 |
+
assert registration["registerOptions"]["triggerCharacters"] == [
|
| 655 |
+
".",
|
| 656 |
+
"@",
|
| 657 |
+
"#",
|
| 658 |
+
"*",
|
| 659 |
+
" ",
|
| 660 |
+
]
|
| 661 |
+
self.completions_available.set()
|
| 662 |
+
if registration["method"] == "workspace/executeCommand":
|
| 663 |
+
if "java.intellicode.enable" in registration["registerOptions"]["commands"]:
|
| 664 |
+
self.intellicode_enable_command_available.set()
|
| 665 |
+
return
|
| 666 |
+
|
| 667 |
+
def lang_status_handler(params):
|
| 668 |
+
# TODO: Should we wait for
|
| 669 |
+
# server -> client: {'jsonrpc': '2.0', 'method': 'language/status', 'params': {'type': 'ProjectStatus', 'message': 'OK'}}
|
| 670 |
+
# Before proceeding?
|
| 671 |
+
if params["type"] == "ServiceReady" and params["message"] == "ServiceReady":
|
| 672 |
+
self.service_ready_event.set()
|
| 673 |
+
|
| 674 |
+
def execute_client_command_handler(params):
|
| 675 |
+
assert params["command"] == "_java.reloadBundles.command"
|
| 676 |
+
assert params["arguments"] == []
|
| 677 |
+
return []
|
| 678 |
+
|
| 679 |
+
def window_log_message(msg):
|
| 680 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 681 |
+
|
| 682 |
+
def do_nothing(params):
|
| 683 |
+
return
|
| 684 |
+
|
| 685 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 686 |
+
self.server.on_notification("language/status", lang_status_handler)
|
| 687 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 688 |
+
self.server.on_request("workspace/executeClientCommand", execute_client_command_handler)
|
| 689 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 690 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 691 |
+
self.server.on_notification("language/actionableNotification", do_nothing)
|
| 692 |
+
|
| 693 |
+
self.logger.log("Starting EclipseJDTLS server process", logging.INFO)
|
| 694 |
+
self.server.start()
|
| 695 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 696 |
+
|
| 697 |
+
self.logger.log(
|
| 698 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 699 |
+
logging.INFO,
|
| 700 |
+
)
|
| 701 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 702 |
+
assert init_response["capabilities"]["textDocumentSync"]["change"] == 2
|
| 703 |
+
assert "completionProvider" not in init_response["capabilities"]
|
| 704 |
+
assert "executeCommandProvider" not in init_response["capabilities"]
|
| 705 |
+
|
| 706 |
+
self.server.notify.initialized({})
|
| 707 |
+
|
| 708 |
+
self.server.notify.workspace_did_change_configuration({"settings": initialize_params["initializationOptions"]["settings"]})
|
| 709 |
+
|
| 710 |
+
self.intellicode_enable_command_available.wait()
|
| 711 |
+
|
| 712 |
+
java_intellisense_members_path = self.runtime_dependency_paths.intellisense_members_path
|
| 713 |
+
assert os.path.exists(java_intellisense_members_path)
|
| 714 |
+
intellicode_enable_result = self.server.send.execute_command(
|
| 715 |
+
{
|
| 716 |
+
"command": "java.intellicode.enable",
|
| 717 |
+
"arguments": [True, java_intellisense_members_path],
|
| 718 |
+
}
|
| 719 |
+
)
|
| 720 |
+
assert intellicode_enable_result
|
| 721 |
+
|
| 722 |
+
# TODO: Add comments about why we wait here, and how this can be optimized
|
| 723 |
+
self.service_ready_event.w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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Erlang Language Server implementation using Erlang LS."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import shutil
|
| 6 |
+
import subprocess
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
|
| 10 |
+
from overrides import override
|
| 11 |
+
|
| 12 |
+
from solidlsp.ls import SolidLanguageServer
|
| 13 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 14 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 15 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 16 |
+
from solidlsp.settings import SolidLSPSettings
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class ErlangLanguageServer(SolidLanguageServer):
|
| 20 |
+
"""Language server for Erlang using Erlang LS."""
|
| 21 |
+
|
| 22 |
+
def __init__(
|
| 23 |
+
self,
|
| 24 |
+
config: LanguageServerConfig,
|
| 25 |
+
logger: LanguageServerLogger,
|
| 26 |
+
repository_root_path: str,
|
| 27 |
+
solidlsp_settings: SolidLSPSettings,
|
| 28 |
+
):
|
| 29 |
+
"""
|
| 30 |
+
Creates an ErlangLanguageServer instance. This class is not meant to be instantiated directly.
|
| 31 |
+
Use LanguageServer.create() instead.
|
| 32 |
+
"""
|
| 33 |
+
self.erlang_ls_path = shutil.which("erlang_ls")
|
| 34 |
+
if not self.erlang_ls_path:
|
| 35 |
+
raise RuntimeError("Erlang LS not found. Install from: https://github.com/erlang-ls/erlang_ls")
|
| 36 |
+
|
| 37 |
+
if not self._check_erlang_installation():
|
| 38 |
+
raise RuntimeError("Erlang/OTP not found. Install from: https://www.erlang.org/downloads")
|
| 39 |
+
|
| 40 |
+
super().__init__(
|
| 41 |
+
config,
|
| 42 |
+
logger,
|
| 43 |
+
repository_root_path,
|
| 44 |
+
ProcessLaunchInfo(cmd=[self.erlang_ls_path, "--transport", "stdio"], cwd=repository_root_path),
|
| 45 |
+
"erlang",
|
| 46 |
+
solidlsp_settings,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Add server readiness tracking like Elixir
|
| 50 |
+
self.server_ready = threading.Event()
|
| 51 |
+
|
| 52 |
+
# Set generous timeout for Erlang LS initialization
|
| 53 |
+
self.set_request_timeout(120.0)
|
| 54 |
+
|
| 55 |
+
def _check_erlang_installation(self) -> bool:
|
| 56 |
+
"""Check if Erlang/OTP is available."""
|
| 57 |
+
try:
|
| 58 |
+
result = subprocess.run(["erl", "-version"], check=False, capture_output=True, text=True, timeout=10)
|
| 59 |
+
return result.returncode == 0
|
| 60 |
+
except (subprocess.SubprocessError, FileNotFoundError):
|
| 61 |
+
return False
|
| 62 |
+
|
| 63 |
+
@classmethod
|
| 64 |
+
def _get_erlang_version(cls):
|
| 65 |
+
"""Get the installed Erlang/OTP version or None if not found."""
|
| 66 |
+
try:
|
| 67 |
+
result = subprocess.run(["erl", "-version"], check=False, capture_output=True, text=True, timeout=10)
|
| 68 |
+
if result.returncode == 0:
|
| 69 |
+
return result.stderr.strip() # erl -version outputs to stderr
|
| 70 |
+
except (subprocess.SubprocessError, FileNotFoundError):
|
| 71 |
+
return None
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
+
@classmethod
|
| 75 |
+
def _check_rebar3_available(cls) -> bool:
|
| 76 |
+
"""Check if rebar3 build tool is available."""
|
| 77 |
+
try:
|
| 78 |
+
result = subprocess.run(["rebar3", "version"], check=False, capture_output=True, text=True, timeout=10)
|
| 79 |
+
return result.returncode == 0
|
| 80 |
+
except (subprocess.SubprocessError, FileNotFoundError):
|
| 81 |
+
return False
|
| 82 |
+
|
| 83 |
+
def _start_server(self):
|
| 84 |
+
"""Start Erlang LS server process with proper initialization waiting."""
|
| 85 |
+
|
| 86 |
+
def register_capability_handler(params):
|
| 87 |
+
return
|
| 88 |
+
|
| 89 |
+
def window_log_message(msg):
|
| 90 |
+
"""Handle window/logMessage notifications from Erlang LS"""
|
| 91 |
+
message_text = msg.get("message", "")
|
| 92 |
+
self.logger.log(f"LSP: window/logMessage: {message_text}", logging.INFO)
|
| 93 |
+
|
| 94 |
+
# Look for Erlang LS readiness signals
|
| 95 |
+
# Common patterns: "Started Erlang LS", "initialized", "ready"
|
| 96 |
+
readiness_signals = [
|
| 97 |
+
"Started Erlang LS",
|
| 98 |
+
"server started",
|
| 99 |
+
"initialized",
|
| 100 |
+
"ready to serve requests",
|
| 101 |
+
"compilation finished",
|
| 102 |
+
"indexing complete",
|
| 103 |
+
]
|
| 104 |
+
|
| 105 |
+
message_lower = message_text.lower()
|
| 106 |
+
for signal in readiness_signals:
|
| 107 |
+
if signal.lower() in message_lower:
|
| 108 |
+
self.logger.log(f"Erlang LS readiness signal detected: {message_text}", logging.INFO)
|
| 109 |
+
self.server_ready.set()
|
| 110 |
+
break
|
| 111 |
+
|
| 112 |
+
def do_nothing(params):
|
| 113 |
+
return
|
| 114 |
+
|
| 115 |
+
def check_server_ready(params):
|
| 116 |
+
"""Handle $/progress notifications from Erlang LS as fallback."""
|
| 117 |
+
value = params.get("value", {})
|
| 118 |
+
|
| 119 |
+
# Check for initialization completion progress
|
| 120 |
+
if value.get("kind") == "end":
|
| 121 |
+
message = value.get("message", "")
|
| 122 |
+
if any(word in message.lower() for word in ["initialized", "ready", "complete"]):
|
| 123 |
+
self.logger.log("Erlang LS initialization progress completed", logging.INFO)
|
| 124 |
+
# Set as fallback if no window/logMessage was received
|
| 125 |
+
if not self.server_ready.is_set():
|
| 126 |
+
self.server_ready.set()
|
| 127 |
+
|
| 128 |
+
# Set up notification handlers
|
| 129 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 130 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 131 |
+
self.server.on_notification("$/progress", check_server_ready)
|
| 132 |
+
self.server.on_notification("window/workDoneProgress/create", do_nothing)
|
| 133 |
+
self.server.on_notification("$/workDoneProgress", do_nothing)
|
| 134 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 135 |
+
|
| 136 |
+
self.logger.log("Starting Erlang LS server process", logging.INFO)
|
| 137 |
+
self.server.start()
|
| 138 |
+
|
| 139 |
+
# Send initialize request
|
| 140 |
+
initialize_params = {
|
| 141 |
+
"processId": None,
|
| 142 |
+
"rootPath": self.repository_root_path,
|
| 143 |
+
"rootUri": f"file://{self.repository_root_path}",
|
| 144 |
+
"capabilities": {
|
| 145 |
+
"textDocument": {
|
| 146 |
+
"synchronization": {"didSave": True},
|
| 147 |
+
"completion": {"dynamicRegistration": True},
|
| 148 |
+
"definition": {"dynamicRegistration": True},
|
| 149 |
+
"references": {"dynamicRegistration": True},
|
| 150 |
+
"documentSymbol": {"dynamicRegistration": True},
|
| 151 |
+
"hover": {"dynamicRegistration": True},
|
| 152 |
+
}
|
| 153 |
+
},
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
self.logger.log("Sending initialize request to Erlang LS", logging.INFO)
|
| 157 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 158 |
+
|
| 159 |
+
# Verify server capabilities
|
| 160 |
+
if "capabilities" in init_response:
|
| 161 |
+
self.logger.log(f"Erlang LS capabilities: {list(init_response['capabilities'].keys())}", logging.INFO)
|
| 162 |
+
|
| 163 |
+
self.server.notify.initialized({})
|
| 164 |
+
self.completions_available.set()
|
| 165 |
+
|
| 166 |
+
# Wait for Erlang LS to be ready - adjust timeout based on environment
|
| 167 |
+
is_ci = os.getenv("CI") == "true" or os.getenv("GITHUB_ACTIONS") == "true"
|
| 168 |
+
is_macos = os.uname().sysname == "Darwin" if hasattr(os, "uname") else False
|
| 169 |
+
|
| 170 |
+
# macOS in CI can be particularly slow for language server startup
|
| 171 |
+
if is_ci and is_macos:
|
| 172 |
+
ready_timeout = 240.0 # 4 minutes for macOS CI
|
| 173 |
+
env_desc = "macOS CI"
|
| 174 |
+
elif is_ci:
|
| 175 |
+
ready_timeout = 180.0 # 3 minutes for other CI
|
| 176 |
+
env_desc = "CI"
|
| 177 |
+
else:
|
| 178 |
+
ready_timeout = 60.0 # 1 minute for local
|
| 179 |
+
env_desc = "local"
|
| 180 |
+
|
| 181 |
+
self.logger.log(f"Waiting up to {ready_timeout} seconds for Erlang LS readiness ({env_desc} environment)...", logging.INFO)
|
| 182 |
+
|
| 183 |
+
if self.server_ready.wait(timeout=ready_timeout):
|
| 184 |
+
self.logger.log("Erlang LS is ready and available for requests", logging.INFO)
|
| 185 |
+
|
| 186 |
+
# Add settling period for indexing - adjust based on environment
|
| 187 |
+
settling_time = 15.0 if is_ci else 5.0
|
| 188 |
+
self.logger.log(f"Allowing {settling_time} seconds for Erlang LS indexing to complete...", logging.INFO)
|
| 189 |
+
time.sleep(settling_time)
|
| 190 |
+
self.logger.log("Erlang LS settling period complete", logging.INFO)
|
| 191 |
+
else:
|
| 192 |
+
# Set ready anyway and continue - Erlang LS might not send explicit ready messages
|
| 193 |
+
self.logger.log(
|
| 194 |
+
f"Erlang LS readiness timeout reached after {ready_timeout}s, proceeding anyway (common in CI)", logging.WARNING
|
| 195 |
+
)
|
| 196 |
+
self.server_ready.set()
|
| 197 |
+
|
| 198 |
+
# Still give some time for basic initialization even without explicit readiness signal
|
| 199 |
+
basic_settling_time = 20.0 if is_ci else 10.0
|
| 200 |
+
self.logger.log(f"Allowing {basic_settling_time} seconds for basic Erlang LS initialization...", logging.INFO)
|
| 201 |
+
time.sleep(basic_settling_time)
|
| 202 |
+
self.logger.log("Basic Erlang LS initialization period complete", logging.INFO)
|
| 203 |
+
|
| 204 |
+
@override
|
| 205 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 206 |
+
# For Erlang projects, we should ignore:
|
| 207 |
+
# - _build: rebar3 build artifacts
|
| 208 |
+
# - deps: dependencies
|
| 209 |
+
# - ebin: compiled beam files
|
| 210 |
+
# - .rebar3: rebar3 cache
|
| 211 |
+
# - logs: log files
|
| 212 |
+
# - node_modules: if the project has JavaScript components
|
| 213 |
+
return super().is_ignored_dirname(dirname) or dirname in [
|
| 214 |
+
"_build",
|
| 215 |
+
"deps",
|
| 216 |
+
"ebin",
|
| 217 |
+
".rebar3",
|
| 218 |
+
"logs",
|
| 219 |
+
"node_modules",
|
| 220 |
+
"_checkouts",
|
| 221 |
+
"cover",
|
| 222 |
+
]
|
| 223 |
+
|
| 224 |
+
def is_ignored_filename(self, filename: str) -> bool:
|
| 225 |
+
"""Check if a filename should be ignored."""
|
| 226 |
+
# Ignore compiled BEAM files
|
| 227 |
+
if filename.endswith(".beam"):
|
| 228 |
+
return True
|
| 229 |
+
# Don't ignore Erlang source files, header files, or configuration files
|
| 230 |
+
return False
|
projects/ui/serena-new/src/solidlsp/language_servers/gopls.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import pathlib
|
| 4 |
+
import subprocess
|
| 5 |
+
import threading
|
| 6 |
+
|
| 7 |
+
from overrides import override
|
| 8 |
+
|
| 9 |
+
from solidlsp.ls import SolidLanguageServer
|
| 10 |
+
from solidlsp.ls_config import LanguageServerConfig
|
| 11 |
+
from solidlsp.ls_logger import LanguageServerLogger
|
| 12 |
+
from solidlsp.lsp_protocol_handler.lsp_types import InitializeParams
|
| 13 |
+
from solidlsp.lsp_protocol_handler.server import ProcessLaunchInfo
|
| 14 |
+
from solidlsp.settings import SolidLSPSettings
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class Gopls(SolidLanguageServer):
|
| 18 |
+
"""
|
| 19 |
+
Provides Go specific instantiation of the LanguageServer class using gopls.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
@override
|
| 23 |
+
def is_ignored_dirname(self, dirname: str) -> bool:
|
| 24 |
+
# For Go projects, we should ignore:
|
| 25 |
+
# - vendor: third-party dependencies vendored into the project
|
| 26 |
+
# - node_modules: if the project has JavaScript components
|
| 27 |
+
# - dist/build: common output directories
|
| 28 |
+
return super().is_ignored_dirname(dirname) or dirname in ["vendor", "node_modules", "dist", "build"]
|
| 29 |
+
|
| 30 |
+
@staticmethod
|
| 31 |
+
def _get_go_version():
|
| 32 |
+
"""Get the installed Go version or None if not found."""
|
| 33 |
+
try:
|
| 34 |
+
result = subprocess.run(["go", "version"], capture_output=True, text=True, check=False)
|
| 35 |
+
if result.returncode == 0:
|
| 36 |
+
return result.stdout.strip()
|
| 37 |
+
except FileNotFoundError:
|
| 38 |
+
return None
|
| 39 |
+
return None
|
| 40 |
+
|
| 41 |
+
@staticmethod
|
| 42 |
+
def _get_gopls_version():
|
| 43 |
+
"""Get the installed gopls version or None if not found."""
|
| 44 |
+
try:
|
| 45 |
+
result = subprocess.run(["gopls", "version"], capture_output=True, text=True, check=False)
|
| 46 |
+
if result.returncode == 0:
|
| 47 |
+
return result.stdout.strip()
|
| 48 |
+
except FileNotFoundError:
|
| 49 |
+
return None
|
| 50 |
+
return None
|
| 51 |
+
|
| 52 |
+
@staticmethod
|
| 53 |
+
def _setup_runtime_dependency():
|
| 54 |
+
"""
|
| 55 |
+
Check if required Go runtime dependencies are available.
|
| 56 |
+
Raises RuntimeError with helpful message if dependencies are missing.
|
| 57 |
+
"""
|
| 58 |
+
go_version = Gopls._get_go_version()
|
| 59 |
+
if not go_version:
|
| 60 |
+
raise RuntimeError(
|
| 61 |
+
"Go is not installed. Please install Go from https://golang.org/doc/install and make sure it is added to your PATH."
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
gopls_version = Gopls._get_gopls_version()
|
| 65 |
+
if not gopls_version:
|
| 66 |
+
raise RuntimeError(
|
| 67 |
+
"Found a Go version but gopls is not installed.\n"
|
| 68 |
+
"Please install gopls as described in https://pkg.go.dev/golang.org/x/tools/gopls#section-readme\n\n"
|
| 69 |
+
"After installation, make sure it is added to your PATH (it might be installed in a different location than Go)."
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
return True
|
| 73 |
+
|
| 74 |
+
def __init__(
|
| 75 |
+
self, config: LanguageServerConfig, logger: LanguageServerLogger, repository_root_path: str, solidlsp_settings: SolidLSPSettings
|
| 76 |
+
):
|
| 77 |
+
self._setup_runtime_dependency()
|
| 78 |
+
|
| 79 |
+
super().__init__(
|
| 80 |
+
config,
|
| 81 |
+
logger,
|
| 82 |
+
repository_root_path,
|
| 83 |
+
ProcessLaunchInfo(cmd="gopls", cwd=repository_root_path),
|
| 84 |
+
"go",
|
| 85 |
+
solidlsp_settings,
|
| 86 |
+
)
|
| 87 |
+
self.server_ready = threading.Event()
|
| 88 |
+
self.request_id = 0
|
| 89 |
+
|
| 90 |
+
@staticmethod
|
| 91 |
+
def _get_initialize_params(repository_absolute_path: str) -> InitializeParams:
|
| 92 |
+
"""
|
| 93 |
+
Returns the initialize params for the Go Language Server.
|
| 94 |
+
"""
|
| 95 |
+
root_uri = pathlib.Path(repository_absolute_path).as_uri()
|
| 96 |
+
initialize_params = {
|
| 97 |
+
"locale": "en",
|
| 98 |
+
"capabilities": {
|
| 99 |
+
"textDocument": {
|
| 100 |
+
"synchronization": {"didSave": True, "dynamicRegistration": True},
|
| 101 |
+
"definition": {"dynamicRegistration": True},
|
| 102 |
+
"documentSymbol": {
|
| 103 |
+
"dynamicRegistration": True,
|
| 104 |
+
"hierarchicalDocumentSymbolSupport": True,
|
| 105 |
+
"symbolKind": {"valueSet": list(range(1, 27))},
|
| 106 |
+
},
|
| 107 |
+
},
|
| 108 |
+
"workspace": {"workspaceFolders": True, "didChangeConfiguration": {"dynamicRegistration": True}},
|
| 109 |
+
},
|
| 110 |
+
"processId": os.getpid(),
|
| 111 |
+
"rootPath": repository_absolute_path,
|
| 112 |
+
"rootUri": root_uri,
|
| 113 |
+
"workspaceFolders": [
|
| 114 |
+
{
|
| 115 |
+
"uri": root_uri,
|
| 116 |
+
"name": os.path.basename(repository_absolute_path),
|
| 117 |
+
}
|
| 118 |
+
],
|
| 119 |
+
}
|
| 120 |
+
return initialize_params
|
| 121 |
+
|
| 122 |
+
def _start_server(self):
|
| 123 |
+
"""Start gopls server process"""
|
| 124 |
+
|
| 125 |
+
def register_capability_handler(params):
|
| 126 |
+
return
|
| 127 |
+
|
| 128 |
+
def window_log_message(msg):
|
| 129 |
+
self.logger.log(f"LSP: window/logMessage: {msg}", logging.INFO)
|
| 130 |
+
|
| 131 |
+
def do_nothing(params):
|
| 132 |
+
return
|
| 133 |
+
|
| 134 |
+
self.server.on_request("client/registerCapability", register_capability_handler)
|
| 135 |
+
self.server.on_notification("window/logMessage", window_log_message)
|
| 136 |
+
self.server.on_notification("$/progress", do_nothing)
|
| 137 |
+
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
|
| 138 |
+
|
| 139 |
+
self.logger.log("Starting gopls server process", logging.INFO)
|
| 140 |
+
self.server.start()
|
| 141 |
+
initialize_params = self._get_initialize_params(self.repository_root_path)
|
| 142 |
+
|
| 143 |
+
self.logger.log(
|
| 144 |
+
"Sending initialize request from LSP client to LSP server and awaiting response",
|
| 145 |
+
logging.INFO,
|
| 146 |
+
)
|
| 147 |
+
init_response = self.server.send.initialize(initialize_params)
|
| 148 |
+
|
| 149 |
+
# Verify server capabilities
|
| 150 |
+
assert "textDocumentSync" in init_response["capabilities"]
|
| 151 |
+
assert "completionProvider" in init_response["capabilities"]
|
| 152 |
+
assert "definitionProvider" in init_response["capabilities"]
|
| 153 |
+
|
| 154 |
+
self.server.notify.initialized({})
|
| 155 |
+
self.completions_available.set()
|
| 156 |
+
|
| 157 |
+
# gopls server is typically ready immediately after initialization
|
| 158 |
+
self.server_ready.set()
|
| 159 |
+
self.server_ready.wait()
|