robotcode-language-server 2.9.0.dev186__py3-none-any.whl → 2.9.0.dev214__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robotcode/language_server/__version__.py +1 -1
- robotcode/language_server/common/parts/documents.py +7 -5
- robotcode/language_server/common/protocol.py +3 -3
- robotcode/language_server/robotframework/parts/code_action_documentation.py +2 -1
- robotcode/language_server/robotframework/parts/code_action_helper_mixin.py +21 -2
- robotcode/language_server/robotframework/parts/code_action_quick_fixes.py +6 -3
- robotcode/language_server/robotframework/parts/code_action_refactor.py +2 -1
- robotcode/language_server/robotframework/parts/code_lens.py +3 -2
- robotcode/language_server/robotframework/parts/completion.py +4 -3
- robotcode/language_server/robotframework/parts/diagnostics.py +9 -8
- robotcode/language_server/robotframework/parts/document_highlight.py +2 -1
- robotcode/language_server/robotframework/parts/document_symbols.py +10 -5
- robotcode/language_server/robotframework/parts/folding_range.py +16 -15
- robotcode/language_server/robotframework/parts/formatting.py +21 -15
- robotcode/language_server/robotframework/parts/goto.py +3 -2
- robotcode/language_server/robotframework/parts/hover.py +2 -1
- robotcode/language_server/robotframework/parts/inlay_hint.py +2 -1
- robotcode/language_server/robotframework/parts/inline_value.py +2 -1
- robotcode/language_server/robotframework/parts/markdown/__init__.py +0 -0
- robotcode/language_server/robotframework/parts/markdown/completion.py +34 -0
- robotcode/language_server/robotframework/parts/markdown/placement.py +49 -0
- robotcode/language_server/robotframework/parts/markdown/ranges.py +86 -0
- robotcode/language_server/robotframework/parts/markdown/robocop.py +82 -0
- robotcode/language_server/robotframework/parts/references.py +6 -5
- robotcode/language_server/robotframework/parts/rename.py +3 -2
- robotcode/language_server/robotframework/parts/robocop_diagnostics.py +17 -13
- robotcode/language_server/robotframework/parts/robot_workspace.py +10 -7
- robotcode/language_server/robotframework/parts/selection_range.py +10 -3
- robotcode/language_server/robotframework/parts/semantic_tokens.py +5 -4
- robotcode/language_server/robotframework/parts/signature_help.py +2 -1
- robotcode/language_server/robotframework/parts/workspace_symbols.py +2 -1
- robotcode/language_server/robotframework/protocol.py +33 -17
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/METADATA +5 -5
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/RECORD +36 -31
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/WHEEL +0 -0
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/entry_points.txt +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.9.0-dev.
|
|
1
|
+
__version__ = "2.9.0-dev.214"
|
|
@@ -92,6 +92,12 @@ class TextDocumentProtocolPart(LanguageServerProtocolPart, DocumentsManager):
|
|
|
92
92
|
callback_filter=language_id_filter(document),
|
|
93
93
|
)
|
|
94
94
|
|
|
95
|
+
def _served_language_id(self, text_document: TextDocumentItem) -> str:
|
|
96
|
+
# editors send `.robot.md` files as `markdown`, a language the server does not serve
|
|
97
|
+
if text_document.language_id in {lang.id for lang in self.languages}:
|
|
98
|
+
return text_document.language_id
|
|
99
|
+
return self.detect_language_id(Uri(text_document.uri))
|
|
100
|
+
|
|
95
101
|
@rpc_method(name="textDocument/didOpen", param_type=DidOpenTextDocumentParams)
|
|
96
102
|
@__logger.call
|
|
97
103
|
def _text_document_did_open(self, text_document: TextDocumentItem, *args: Any, **kwargs: Any) -> None:
|
|
@@ -106,11 +112,7 @@ class TextDocumentProtocolPart(LanguageServerProtocolPart, DocumentsManager):
|
|
|
106
112
|
document = self._create_document(
|
|
107
113
|
text_document.uri,
|
|
108
114
|
normalized_text,
|
|
109
|
-
(
|
|
110
|
-
text_document.language_id
|
|
111
|
-
if text_document.language_id
|
|
112
|
-
else self.detect_language_id(text_document.uri)
|
|
113
|
-
),
|
|
115
|
+
self._served_language_id(text_document),
|
|
114
116
|
text_document.version,
|
|
115
117
|
)
|
|
116
118
|
|
|
@@ -2,7 +2,7 @@ import asyncio
|
|
|
2
2
|
import logging
|
|
3
3
|
import threading
|
|
4
4
|
from threading import Event
|
|
5
|
-
from typing import Any,
|
|
5
|
+
from typing import Any, Final, List, Optional, Set, Union
|
|
6
6
|
|
|
7
7
|
from robotcode.core.concurrent import Task
|
|
8
8
|
from robotcode.core.event import event
|
|
@@ -132,8 +132,8 @@ class LanguageServerProtocol(JsonRPCProtocol):
|
|
|
132
132
|
progress_title: Optional[str] = None
|
|
133
133
|
version: Optional[str] = None
|
|
134
134
|
|
|
135
|
-
file_extensions:
|
|
136
|
-
language_definitions:
|
|
135
|
+
file_extensions: Set[str] = set()
|
|
136
|
+
language_definitions: List[LanguageDefinition] = []
|
|
137
137
|
|
|
138
138
|
def __init__(self, server: JsonRPCServer[Any]):
|
|
139
139
|
super().__init__()
|
|
@@ -36,6 +36,7 @@ from robotcode.robot.diagnostics.semantic_analyzer.nodes import (
|
|
|
36
36
|
DefinitionStatement,
|
|
37
37
|
ImportStatement,
|
|
38
38
|
)
|
|
39
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
39
40
|
from robotcode.robot.utils.ast import get_node_at_position, range_from_token
|
|
40
41
|
from robotcode.robot.utils.markdown_docs import (
|
|
41
42
|
REFERENCE_KEYWORD,
|
|
@@ -244,7 +245,7 @@ class RobotCodeActionDocumentationProtocolPart(RobotLanguageServerProtocolPart,
|
|
|
244
245
|
|
|
245
246
|
parent.code_action.collect.add(self.collect)
|
|
246
247
|
|
|
247
|
-
@language_id(
|
|
248
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
248
249
|
@code_action_kinds([CodeActionKind.SOURCE])
|
|
249
250
|
@_logger.call
|
|
250
251
|
def collect(
|
|
@@ -2,14 +2,18 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import ast
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
-
from typing import List, Optional, Tuple, Union
|
|
5
|
+
from typing import TYPE_CHECKING, List, Optional, Tuple, Union
|
|
6
6
|
|
|
7
|
+
from robotcode.core.language import language_id_filter
|
|
7
8
|
from robotcode.core.lsp.types import CodeActionContext, CodeActionKind, DocumentUri, Position, Range
|
|
8
9
|
from robotcode.core.text_document import TextDocument
|
|
9
10
|
from robotcode.robot.diagnostics.namespace import Namespace
|
|
10
11
|
from robotcode.robot.utils.ast import range_from_node
|
|
11
12
|
from robotcode.robot.utils.visitor import Visitor
|
|
12
13
|
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from ..protocol import RobotLanguageServerProtocol
|
|
16
|
+
|
|
13
17
|
SHOW_DOCUMENT_SELECT_AND_RENAME_COMMAND = "_robotcode.codeActionShowDocumentSelectAndRename"
|
|
14
18
|
|
|
15
19
|
|
|
@@ -72,6 +76,21 @@ def find_keyword_sections(node: ast.AST) -> Optional[List[ast.AST]]:
|
|
|
72
76
|
|
|
73
77
|
|
|
74
78
|
class CodeActionHelperMixin:
|
|
79
|
+
if TYPE_CHECKING:
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def parent(self) -> RobotLanguageServerProtocol: ...
|
|
83
|
+
|
|
84
|
+
def place_code(self, document: TextDocument, text: str, range: Range) -> Tuple[str, Range]:
|
|
85
|
+
"""The text and range of code that a code action places, as the language of the document places it."""
|
|
86
|
+
for result in self.parent.place_code(self, document, text, range, callback_filter=language_id_filter(document)):
|
|
87
|
+
if isinstance(result, BaseException):
|
|
88
|
+
raise result
|
|
89
|
+
if result is not None:
|
|
90
|
+
return result
|
|
91
|
+
|
|
92
|
+
return text, range
|
|
93
|
+
|
|
75
94
|
def create_insert_keyword_workspace_edit(
|
|
76
95
|
self,
|
|
77
96
|
document: TextDocument,
|
|
@@ -117,4 +136,4 @@ class CodeActionHelperMixin:
|
|
|
117
136
|
and lines[insert_range.start.line + 1].startswith("*")
|
|
118
137
|
):
|
|
119
138
|
insert_text = insert_text + "\n"
|
|
120
|
-
return insert_text, insert_range
|
|
139
|
+
return self.place_code(document, insert_text, insert_range)
|
|
@@ -56,6 +56,7 @@ from robotcode.robot.diagnostics.namespace import Namespace
|
|
|
56
56
|
from robotcode.robot.diagnostics.semantic_analyzer.enums import TokenKind
|
|
57
57
|
from robotcode.robot.diagnostics.semantic_analyzer.model import SemanticModel
|
|
58
58
|
from robotcode.robot.diagnostics.semantic_analyzer.nodes import KeywordCallStatement
|
|
59
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
59
60
|
from robotcode.robot.utils.ast import (
|
|
60
61
|
FirstAndLastRealStatementFinder,
|
|
61
62
|
get_node_at_position,
|
|
@@ -134,7 +135,7 @@ class RobotCodeActionQuickFixesProtocolPart(RobotLanguageServerProtocolPart, Mod
|
|
|
134
135
|
|
|
135
136
|
self.parent.commands.register_all(self)
|
|
136
137
|
|
|
137
|
-
@language_id(
|
|
138
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
138
139
|
@code_action_kinds([CodeActionKind.QUICK_FIX])
|
|
139
140
|
def collect(
|
|
140
141
|
self,
|
|
@@ -374,7 +375,7 @@ class RobotCodeActionQuickFixesProtocolPart(RobotLanguageServerProtocolPart, Mod
|
|
|
374
375
|
|
|
375
376
|
lines = insert_text.rstrip().splitlines()
|
|
376
377
|
selection_range = insert_range.extend(start_line=len(lines) - 1, end_line=len(lines) - 1)
|
|
377
|
-
selection_range.start.character =
|
|
378
|
+
selection_range.start.character = len(lines[-1]) - len(lines[-1].lstrip())
|
|
378
379
|
selection_range.end.character = len(lines[-1])
|
|
379
380
|
|
|
380
381
|
return we, selection_range
|
|
@@ -682,7 +683,9 @@ class RobotCodeActionQuickFixesProtocolPart(RobotLanguageServerProtocolPart, Mod
|
|
|
682
683
|
insert_range.start.line = len(lines) - 1
|
|
683
684
|
insert_range.start.character = len(lines[-1])
|
|
684
685
|
insert_range_prefix = "\n" + insert_range_prefix
|
|
685
|
-
insert_text =
|
|
686
|
+
insert_text, insert_range = self.place_code(
|
|
687
|
+
document, insert_range_prefix + f"${{{text}}} value\n" + insert_range_suffix, insert_range
|
|
688
|
+
)
|
|
686
689
|
|
|
687
690
|
code_action.edit = WorkspaceEdit(
|
|
688
691
|
document_changes=[
|
|
@@ -29,6 +29,7 @@ from robotcode.robot.diagnostics.namespace import Namespace
|
|
|
29
29
|
from robotcode.robot.diagnostics.semantic_analyzer.enums import NodeKind, TokenKind
|
|
30
30
|
from robotcode.robot.diagnostics.semantic_analyzer.model import SemanticModel
|
|
31
31
|
from robotcode.robot.diagnostics.semantic_analyzer.nodes import KeywordCallStatement
|
|
32
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
32
33
|
from robotcode.robot.utils.ast import (
|
|
33
34
|
get_nodes_at_position,
|
|
34
35
|
iter_nodes,
|
|
@@ -107,7 +108,7 @@ class RobotCodeActionRefactorProtocolPart(RobotLanguageServerProtocolPart, CodeA
|
|
|
107
108
|
|
|
108
109
|
self.parent.commands.register_all(self)
|
|
109
110
|
|
|
110
|
-
@language_id(
|
|
111
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
111
112
|
@code_action_kinds(
|
|
112
113
|
[
|
|
113
114
|
CODE_ACTION_KIND_REFACTOR_EXTRACT_FUNCTION,
|
|
@@ -8,6 +8,7 @@ from robotcode.core.text_document import TextDocument
|
|
|
8
8
|
from robotcode.core.utils.logging import LoggingDescriptor
|
|
9
9
|
from robotcode.language_server.robotframework.configuration import AnalysisConfig
|
|
10
10
|
from robotcode.robot.diagnostics.library_doc import KeywordDoc
|
|
11
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
11
12
|
from robotcode.robot.utils.ast import range_from_token
|
|
12
13
|
from robotcode.robot.utils.visitor import Visitor
|
|
13
14
|
|
|
@@ -46,13 +47,13 @@ class RobotCodeLensProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
46
47
|
if self.enabled:
|
|
47
48
|
self.parent.code_lens.refresh()
|
|
48
49
|
|
|
49
|
-
@language_id(
|
|
50
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
50
51
|
def collect(self, sender: Any, document: TextDocument) -> Optional[List[CodeLens]]:
|
|
51
52
|
if self.enabled and self.parent.workspace.get_configuration(AnalysisConfig, document.uri).references_code_lens:
|
|
52
53
|
return _Visitor.find_from(self.parent.documents_cache.get_model(document), self, document)
|
|
53
54
|
return None
|
|
54
55
|
|
|
55
|
-
@language_id(
|
|
56
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
56
57
|
def resolve(self, sender: Any, code_lens: CodeLens) -> Optional[CodeLens]:
|
|
57
58
|
if not self.enabled:
|
|
58
59
|
return None
|
|
@@ -75,6 +75,7 @@ from robotcode.robot.diagnostics.library_doc import (
|
|
|
75
75
|
)
|
|
76
76
|
from robotcode.robot.diagnostics.model_helper import ModelHelper
|
|
77
77
|
from robotcode.robot.diagnostics.namespace import DocumentType, Namespace
|
|
78
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS, ROBOTFRAMEWORK_LANGUAGE_ID
|
|
78
79
|
from robotcode.robot.utils import RF_VERSION
|
|
79
80
|
from robotcode.robot.utils.ast import (
|
|
80
81
|
get_nodes_at_position,
|
|
@@ -142,7 +143,7 @@ class RobotCompletionProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
142
143
|
|
|
143
144
|
return DEFAULT_HEADER_STYLE if RF_VERSION < (6, 0) else DEFAULT_HEADER_STYLE_51
|
|
144
145
|
|
|
145
|
-
@language_id(
|
|
146
|
+
@language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
|
|
146
147
|
@trigger_characters(
|
|
147
148
|
[
|
|
148
149
|
" ",
|
|
@@ -157,7 +158,7 @@ class RobotCompletionProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
157
158
|
]
|
|
158
159
|
)
|
|
159
160
|
# @all_commit_characters(['\n'])
|
|
160
|
-
@language_id(
|
|
161
|
+
@language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
|
|
161
162
|
@_logger.call
|
|
162
163
|
def collect(
|
|
163
164
|
self,
|
|
@@ -180,7 +181,7 @@ class RobotCompletionProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
180
181
|
config,
|
|
181
182
|
).collect(position, context)
|
|
182
183
|
|
|
183
|
-
@language_id(
|
|
184
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
184
185
|
@_logger.call
|
|
185
186
|
def resolve(self, sender: Any, completion_item: CompletionItem) -> CompletionItem:
|
|
186
187
|
if completion_item.data is not None:
|
|
@@ -22,6 +22,7 @@ from robotcode.robot.diagnostics.entities import (
|
|
|
22
22
|
)
|
|
23
23
|
from robotcode.robot.diagnostics.library_doc import LibraryDoc
|
|
24
24
|
from robotcode.robot.diagnostics.namespace import Namespace
|
|
25
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
25
26
|
|
|
26
27
|
from ...common.parts.diagnostics import DiagnosticsCollectType, DiagnosticsResult
|
|
27
28
|
|
|
@@ -80,11 +81,11 @@ class RobotDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
80
81
|
if any(lib_doc in lib_docs for lib_doc in variables):
|
|
81
82
|
self.parent.diagnostics.force_refresh_document(doc)
|
|
82
83
|
|
|
83
|
-
@language_id(
|
|
84
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
84
85
|
def analyze(self, sender: Any, document: TextDocument) -> None:
|
|
85
86
|
self.parent.documents_cache.get_namespace(document).analyze()
|
|
86
87
|
|
|
87
|
-
@language_id(
|
|
88
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
88
89
|
def _on_namespace_initialized(self, sender: Any, namespace: Namespace) -> None:
|
|
89
90
|
# only a document open in the editor: a closed one gets its diagnostics renewed through the invalidation
|
|
90
91
|
# that started the rebuild or through its own changes, marking it again would analyze it once more
|
|
@@ -93,14 +94,14 @@ class RobotDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
93
94
|
# loop holds the diagnostics lock when it waits for a task that may wait for that entry
|
|
94
95
|
run_as_task(self.parent.diagnostics.force_refresh_document, namespace.document)
|
|
95
96
|
|
|
96
|
-
@language_id(
|
|
97
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
97
98
|
def _on_namespace_invalidated(self, sender: Any, namespace: Namespace) -> None:
|
|
98
99
|
if namespace.document is not None:
|
|
99
100
|
# also a closed document: the workspace diagnostics loop renews its analysis, which refreshes its
|
|
100
101
|
# references and diagnostics
|
|
101
102
|
run_as_task(self.parent.diagnostics.force_refresh_document, namespace.document)
|
|
102
103
|
|
|
103
|
-
@language_id(
|
|
104
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
104
105
|
def _on_get_related_documents(self, sender: Any, document: TextDocument) -> Optional[List[TextDocument]]:
|
|
105
106
|
namespace = self.parent.documents_cache.get_only_initialized_namespace(document)
|
|
106
107
|
if namespace is None:
|
|
@@ -110,7 +111,7 @@ class RobotDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
110
111
|
|
|
111
112
|
lib_doc = namespace.library_doc
|
|
112
113
|
for doc in self.parent.documents.documents:
|
|
113
|
-
if doc.language_id
|
|
114
|
+
if doc.language_id not in ROBOT_LANGUAGE_IDS:
|
|
114
115
|
continue
|
|
115
116
|
|
|
116
117
|
doc_namespace = self.parent.documents_cache.get_only_initialized_namespace(doc)
|
|
@@ -127,7 +128,7 @@ class RobotDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
127
128
|
def modify_diagnostics(self, document: TextDocument, diagnostics: List[Diagnostic]) -> List[Diagnostic]:
|
|
128
129
|
return self.parent.documents_cache.get_diagnostic_modifier(document).modify_diagnostics(diagnostics)
|
|
129
130
|
|
|
130
|
-
@language_id(
|
|
131
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
131
132
|
def collect_namespace_diagnostics(
|
|
132
133
|
self, sender: Any, document: TextDocument, diagnostics_type: DiagnosticsCollectType
|
|
133
134
|
) -> DiagnosticsResult:
|
|
@@ -160,7 +161,7 @@ class RobotDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
160
161
|
],
|
|
161
162
|
)
|
|
162
163
|
|
|
163
|
-
@language_id(
|
|
164
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
164
165
|
@_logger.call
|
|
165
166
|
def collect_unused_keyword_references(
|
|
166
167
|
self, sender: Any, document: TextDocument, diagnostics_type: DiagnosticsCollectType
|
|
@@ -219,7 +220,7 @@ class RobotDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
219
220
|
],
|
|
220
221
|
)
|
|
221
222
|
|
|
222
|
-
@language_id(
|
|
223
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
223
224
|
@_logger.call
|
|
224
225
|
def collect_unused_variable_references(
|
|
225
226
|
self, sender: Any, document: TextDocument, diagnostics_type: DiagnosticsCollectType
|
|
@@ -10,6 +10,7 @@ from robotcode.core.lsp.types import (
|
|
|
10
10
|
)
|
|
11
11
|
from robotcode.core.text_document import TextDocument
|
|
12
12
|
from robotcode.core.utils.logging import LoggingDescriptor
|
|
13
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
13
14
|
|
|
14
15
|
if TYPE_CHECKING:
|
|
15
16
|
from ..protocol import RobotLanguageServerProtocol
|
|
@@ -25,7 +26,7 @@ class RobotDocumentHighlightProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
25
26
|
|
|
26
27
|
parent.document_highlight.collect.add(self.collect)
|
|
27
28
|
|
|
28
|
-
@language_id(
|
|
29
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
29
30
|
@_logger.call
|
|
30
31
|
def collect(self, sender: Any, document: TextDocument, position: Position) -> Optional[List[DocumentHighlight]]:
|
|
31
32
|
namespace = self.parent.documents_cache.get_namespace(document)
|
|
@@ -10,11 +10,13 @@ from robot.parsing.model.statements import Statement
|
|
|
10
10
|
from robotcode.core.language import language_id
|
|
11
11
|
from robotcode.core.lsp.types import (
|
|
12
12
|
DocumentSymbol,
|
|
13
|
+
Range,
|
|
13
14
|
SymbolInformation,
|
|
14
15
|
SymbolKind,
|
|
15
16
|
)
|
|
16
17
|
from robotcode.core.text_document import TextDocument
|
|
17
18
|
from robotcode.core.utils.logging import LoggingDescriptor
|
|
19
|
+
from robotcode.robot.language_definitions import ROBOTFRAMEWORK_LANGUAGE_ID
|
|
18
20
|
from robotcode.robot.utils.ast import (
|
|
19
21
|
range_from_node,
|
|
20
22
|
range_from_token,
|
|
@@ -37,7 +39,7 @@ class RobotDocumentSymbolsProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
37
39
|
|
|
38
40
|
parent.document_symbols.collect.add(self.collect)
|
|
39
41
|
|
|
40
|
-
@language_id(
|
|
42
|
+
@language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
|
|
41
43
|
@_logger.call
|
|
42
44
|
def collect(
|
|
43
45
|
self, sender: Any, document: TextDocument
|
|
@@ -69,11 +71,14 @@ class _Visitor(Visitor):
|
|
|
69
71
|
|
|
70
72
|
return finder.result if finder.result else None
|
|
71
73
|
|
|
74
|
+
def node_range(self, node: ast.AST) -> Range:
|
|
75
|
+
return range_from_node(node)
|
|
76
|
+
|
|
72
77
|
def visit_Section(self, node: Section) -> None: # noqa: N802
|
|
73
78
|
if not node.header or not node.header.name:
|
|
74
79
|
return
|
|
75
80
|
|
|
76
|
-
r =
|
|
81
|
+
r = self.node_range(node)
|
|
77
82
|
symbol = DocumentSymbol(
|
|
78
83
|
name=node.header.name,
|
|
79
84
|
kind=SymbolKind.MODULE,
|
|
@@ -91,7 +96,7 @@ class _Visitor(Visitor):
|
|
|
91
96
|
return
|
|
92
97
|
|
|
93
98
|
if self.current_symbol is not None and self.current_symbol.children is not None:
|
|
94
|
-
r =
|
|
99
|
+
r = self.node_range(node)
|
|
95
100
|
symbol = DocumentSymbol(
|
|
96
101
|
name=node.name,
|
|
97
102
|
kind=SymbolKind.CLASS,
|
|
@@ -108,7 +113,7 @@ class _Visitor(Visitor):
|
|
|
108
113
|
return
|
|
109
114
|
|
|
110
115
|
if self.current_symbol is not None and self.current_symbol.children is not None:
|
|
111
|
-
r =
|
|
116
|
+
r = self.node_range(node)
|
|
112
117
|
symbol = DocumentSymbol(
|
|
113
118
|
name=node.name,
|
|
114
119
|
kind=SymbolKind.FUNCTION,
|
|
@@ -270,6 +275,6 @@ class _Visitor(Visitor):
|
|
|
270
275
|
if node.tokens[:1]:
|
|
271
276
|
r = range_from_token(node.tokens[0])
|
|
272
277
|
else:
|
|
273
|
-
r =
|
|
278
|
+
r = self.node_range(node)
|
|
274
279
|
symbol = DocumentSymbol(name=name, kind=SymbolKind.VARIABLE, range=r, selection_range=r)
|
|
275
280
|
self.current_symbol.children.append(symbol)
|
|
@@ -10,6 +10,7 @@ from robotcode.core.language import language_id
|
|
|
10
10
|
from robotcode.core.lsp.types import FoldingRange
|
|
11
11
|
from robotcode.core.text_document import TextDocument
|
|
12
12
|
from robotcode.core.utils.logging import LoggingDescriptor
|
|
13
|
+
from robotcode.robot.language_definitions import ROBOTFRAMEWORK_LANGUAGE_ID
|
|
13
14
|
from robotcode.robot.utils.visitor import Visitor
|
|
14
15
|
|
|
15
16
|
from .protocol_part import RobotLanguageServerProtocolPart
|
|
@@ -50,7 +51,7 @@ class _Visitor(Visitor):
|
|
|
50
51
|
|
|
51
52
|
return finder.result if finder.result else None
|
|
52
53
|
|
|
53
|
-
def
|
|
54
|
+
def _append(self, start_node: ast.AST, kind: str, end_node: Optional[ast.AST] = None) -> None:
|
|
54
55
|
if end_node is None:
|
|
55
56
|
end_node = start_node
|
|
56
57
|
if not self.line_folding_only:
|
|
@@ -73,51 +74,51 @@ class _Visitor(Visitor):
|
|
|
73
74
|
)
|
|
74
75
|
|
|
75
76
|
def visit_Section(self, node: ast.AST) -> None: # noqa: N802
|
|
76
|
-
self.
|
|
77
|
+
self._append(node, kind="section")
|
|
77
78
|
|
|
78
79
|
self.generic_visit(node)
|
|
79
80
|
|
|
80
81
|
def visit_CommentSection(self, node: ast.AST) -> None: # noqa: N802
|
|
81
|
-
self.
|
|
82
|
+
self._append(node, kind="comment")
|
|
82
83
|
self.generic_visit(node)
|
|
83
84
|
|
|
84
85
|
def visit_Documentation(self, node: ast.AST) -> None: # noqa: N802
|
|
85
|
-
self.
|
|
86
|
+
self._append(node, kind="documentation")
|
|
86
87
|
self.generic_visit(node)
|
|
87
88
|
|
|
88
89
|
def visit_TestCase(self, node: TestCase) -> None: # noqa: N802
|
|
89
90
|
if node.name:
|
|
90
|
-
self.
|
|
91
|
+
self._append(node, kind="testcase")
|
|
91
92
|
self.generic_visit(node)
|
|
92
93
|
|
|
93
94
|
def visit_Keyword(self, node: Keyword) -> None: # noqa: N802
|
|
94
95
|
if node.name:
|
|
95
|
-
self.
|
|
96
|
+
self._append(node, kind="keyword")
|
|
96
97
|
self.generic_visit(node)
|
|
97
98
|
|
|
98
99
|
def visit_ForLoop(self, node: ast.AST) -> None: # noqa: N802
|
|
99
|
-
self.
|
|
100
|
+
self._append(node, kind="for_loop")
|
|
100
101
|
self.generic_visit(node)
|
|
101
102
|
|
|
102
103
|
def visit_Group(self, node: ast.AST) -> None: # noqa: N802
|
|
103
|
-
self.
|
|
104
|
+
self._append(node, kind="group")
|
|
104
105
|
self.generic_visit(node)
|
|
105
106
|
|
|
106
107
|
def visit_For(self, node: ast.AST) -> None: # noqa: N802
|
|
107
|
-
self.
|
|
108
|
+
self._append(node, kind="for")
|
|
108
109
|
self.generic_visit(node)
|
|
109
110
|
|
|
110
111
|
def visit_If(self, node: If) -> None: # noqa: N802
|
|
111
112
|
if node.orelse is not None and node.body[-1]:
|
|
112
|
-
self.
|
|
113
|
+
self._append(node, kind="if", end_node=node.body[-1])
|
|
113
114
|
elif node.orelse is None and node.type == "ELSE":
|
|
114
|
-
self.
|
|
115
|
+
self._append(
|
|
115
116
|
node,
|
|
116
117
|
kind="if",
|
|
117
118
|
end_node=self.current_if[-1] if self.current_if else None,
|
|
118
119
|
)
|
|
119
120
|
else:
|
|
120
|
-
self.
|
|
121
|
+
self._append(node, kind="if")
|
|
121
122
|
|
|
122
123
|
if node.type == "IF":
|
|
123
124
|
self.current_if.append(node)
|
|
@@ -128,11 +129,11 @@ class _Visitor(Visitor):
|
|
|
128
129
|
self.current_if.remove(node)
|
|
129
130
|
|
|
130
131
|
def visit_While(self, node: While) -> None: # noqa: N802
|
|
131
|
-
self.
|
|
132
|
+
self._append(node, kind="while")
|
|
132
133
|
self.generic_visit(node)
|
|
133
134
|
|
|
134
135
|
def visit_Try(self, node: Try) -> None: # noqa: N802
|
|
135
|
-
self.
|
|
136
|
+
self._append(node, kind="try", end_node=node.body[-1] if node.body else None)
|
|
136
137
|
self.generic_visit(node)
|
|
137
138
|
|
|
138
139
|
|
|
@@ -144,7 +145,7 @@ class RobotFoldingRangeProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
144
145
|
|
|
145
146
|
parent.folding_ranges.collect.add(self.collect)
|
|
146
147
|
|
|
147
|
-
@language_id(
|
|
148
|
+
@language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
|
|
148
149
|
@_logger.call
|
|
149
150
|
def collect(self, sender: Any, document: TextDocument) -> Optional[List[FoldingRange]]:
|
|
150
151
|
return _Visitor.find_from(self.parent.documents_cache.get_model(document), self)
|
|
@@ -11,11 +11,14 @@ from robotcode.core.lsp.types import (
|
|
|
11
11
|
)
|
|
12
12
|
from robotcode.core.text_document import TextDocument
|
|
13
13
|
from robotcode.core.utils.logging import LoggingDescriptor
|
|
14
|
+
from robotcode.robot.language_definitions import ROBOTFRAMEWORK_LANGUAGE_ID
|
|
14
15
|
|
|
15
16
|
from ..configuration import RoboCopConfig
|
|
16
17
|
from .protocol_part import RobotLanguageServerProtocolPart
|
|
17
18
|
|
|
18
19
|
if TYPE_CHECKING:
|
|
20
|
+
from robocop.formatter.runner import RobocopFormatter
|
|
21
|
+
|
|
19
22
|
from ..protocol import RobotLanguageServerProtocol
|
|
20
23
|
|
|
21
24
|
|
|
@@ -44,7 +47,7 @@ class RobotFormattingProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
44
47
|
|
|
45
48
|
return self.parent.workspace.get_configuration(RoboCopConfig, folder.uri)
|
|
46
49
|
|
|
47
|
-
@language_id(
|
|
50
|
+
@language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
|
|
48
51
|
@_logger.call
|
|
49
52
|
def format(
|
|
50
53
|
self,
|
|
@@ -78,7 +81,6 @@ class RobotFormattingProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
78
81
|
|
|
79
82
|
config_manager = self.parent.robocop_helper.get_config_manager(workspace_folder)
|
|
80
83
|
|
|
81
|
-
source = document.uri.to_path()
|
|
82
84
|
config = config_manager.get_config_for_source_file(document.uri.to_path())
|
|
83
85
|
|
|
84
86
|
if range is not None:
|
|
@@ -89,17 +91,8 @@ class RobotFormattingProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
89
91
|
runner = RobocopFormatter(config_manager)
|
|
90
92
|
runner.config = config
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
if
|
|
94
|
-
from robocop.source_file import SourceFile
|
|
95
|
-
|
|
96
|
-
# overwrite _model to stop Robocop from loading it
|
|
97
|
-
source_file = SourceFile(path=source, config=config, _model=model)
|
|
98
|
-
_, _, new, _ = runner.format_until_stable(source_file)
|
|
99
|
-
else:
|
|
100
|
-
_, _, new, _ = runner.format_until_stable(model)
|
|
101
|
-
|
|
102
|
-
if new.text == document.text():
|
|
94
|
+
new_text = self.formatted_text(runner, document, config)
|
|
95
|
+
if new_text == document.text():
|
|
103
96
|
return None
|
|
104
97
|
|
|
105
98
|
return [
|
|
@@ -108,11 +101,24 @@ class RobotFormattingProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
108
101
|
start=Position(line=0, character=0),
|
|
109
102
|
end=Position(line=len(document.get_lines()), character=0),
|
|
110
103
|
),
|
|
111
|
-
new_text=
|
|
104
|
+
new_text=new_text,
|
|
112
105
|
)
|
|
113
106
|
]
|
|
114
107
|
|
|
115
|
-
|
|
108
|
+
def formatted_text(self, runner: "RobocopFormatter", document: TextDocument, config: Any) -> str:
|
|
109
|
+
model = self.parent.documents_cache.get_uncached_model(document)
|
|
110
|
+
if self.parent.robocop_helper.robocop_version >= (8, 0):
|
|
111
|
+
from robocop.source_file import SourceFile
|
|
112
|
+
|
|
113
|
+
# overwrite _model to stop Robocop from loading it
|
|
114
|
+
source_file = SourceFile(path=document.uri.to_path(), config=config, _model=model)
|
|
115
|
+
_, _, new, _ = runner.format_until_stable(source_file)
|
|
116
|
+
else:
|
|
117
|
+
_, _, new, _ = runner.format_until_stable(model)
|
|
118
|
+
|
|
119
|
+
return str(new.text)
|
|
120
|
+
|
|
121
|
+
@language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
|
|
116
122
|
def format_range(
|
|
117
123
|
self,
|
|
118
124
|
sender: Any,
|
|
@@ -8,6 +8,7 @@ from robotcode.core.lsp.types import Location, LocationLink, Position
|
|
|
8
8
|
from robotcode.core.text_document import TextDocument
|
|
9
9
|
from robotcode.core.uri import Uri
|
|
10
10
|
from robotcode.core.utils.logging import LoggingDescriptor
|
|
11
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
11
12
|
from robotcode.robot.utils.ast import range_from_token
|
|
12
13
|
|
|
13
14
|
from .protocol_part import RobotLanguageServerProtocolPart
|
|
@@ -25,14 +26,14 @@ class RobotGotoProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
25
26
|
parent.definition.collect.add(self.collect_definition)
|
|
26
27
|
parent.implementation.collect.add(self.collect_implementation)
|
|
27
28
|
|
|
28
|
-
@language_id(
|
|
29
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
29
30
|
@_logger.call
|
|
30
31
|
def collect_definition(
|
|
31
32
|
self, sender: Any, document: TextDocument, position: Position
|
|
32
33
|
) -> Union[Location, List[Location], List[LocationLink], None]:
|
|
33
34
|
return self.collect(document, position)
|
|
34
35
|
|
|
35
|
-
@language_id(
|
|
36
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
36
37
|
@_logger.call
|
|
37
38
|
def collect_implementation(
|
|
38
39
|
self, sender: Any, document: TextDocument, position: Position
|
|
@@ -36,6 +36,7 @@ from robotcode.robot.diagnostics.entities import (
|
|
|
36
36
|
)
|
|
37
37
|
from robotcode.robot.diagnostics.library_doc import KeywordDoc
|
|
38
38
|
from robotcode.robot.diagnostics.namespace import Namespace
|
|
39
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
39
40
|
from robotcode.robot.utils.ast import (
|
|
40
41
|
get_nodes_at_position,
|
|
41
42
|
range_from_node,
|
|
@@ -87,7 +88,7 @@ class RobotHoverProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
87
88
|
|
|
88
89
|
return None
|
|
89
90
|
|
|
90
|
-
@language_id(
|
|
91
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
91
92
|
@_logger.call
|
|
92
93
|
def collect(self, sender: Any, document: TextDocument, position: Position) -> Optional[Hover]:
|
|
93
94
|
model = self.parent.documents_cache.get_model(document)
|
|
@@ -33,6 +33,7 @@ if TYPE_CHECKING:
|
|
|
33
33
|
from ..protocol import RobotLanguageServerProtocol
|
|
34
34
|
|
|
35
35
|
from robotcode.robot.diagnostics.model_helper import ModelHelper
|
|
36
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
36
37
|
|
|
37
38
|
from .protocol_part import RobotLanguageServerProtocolPart
|
|
38
39
|
|
|
@@ -72,7 +73,7 @@ class RobotInlayHintProtocolPart(RobotLanguageServerProtocolPart, ModelHelper):
|
|
|
72
73
|
|
|
73
74
|
return None
|
|
74
75
|
|
|
75
|
-
@language_id(
|
|
76
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
76
77
|
@_logger.call
|
|
77
78
|
def collect(self, sender: Any, document: TextDocument, range: Range) -> Optional[List[InlayHint]]:
|
|
78
79
|
config = self.get_config(document)
|
|
@@ -19,6 +19,7 @@ from robotcode.robot.diagnostics.model_helper import ModelHelper
|
|
|
19
19
|
from robotcode.robot.diagnostics.semantic_analyzer.enums import NodeKind
|
|
20
20
|
from robotcode.robot.diagnostics.semantic_analyzer.model import SemanticModel
|
|
21
21
|
from robotcode.robot.diagnostics.semantic_analyzer.nodes import SemanticToken
|
|
22
|
+
from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
|
|
22
23
|
from robotcode.robot.utils.ast import (
|
|
23
24
|
iter_nodes,
|
|
24
25
|
range_from_node,
|
|
@@ -44,7 +45,7 @@ class RobotInlineValueProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
44
45
|
|
|
45
46
|
parent.inline_value.collect.add(self.collect)
|
|
46
47
|
|
|
47
|
-
@language_id(
|
|
48
|
+
@language_id(*ROBOT_LANGUAGE_IDS)
|
|
48
49
|
@_logger.call
|
|
49
50
|
def collect(
|
|
50
51
|
self,
|
|
File without changes
|