robotcode-language-server 2.9.0.dev186__py3-none-any.whl → 2.9.0.dev197__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 +2 -1
- 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 +8 -4
- robotcode/language_server/robotframework/parts/folding_range.py +14 -14
- robotcode/language_server/robotframework/parts/formatting.py +18 -13
- 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 +80 -0
- robotcode/language_server/robotframework/parts/references.py +8 -5
- robotcode/language_server/robotframework/parts/rename.py +3 -2
- robotcode/language_server/robotframework/parts/robocop_diagnostics.py +15 -12
- robotcode/language_server/robotframework/parts/robot_workspace.py +10 -7
- robotcode/language_server/robotframework/parts/selection_range.py +8 -2
- 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 -4
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev197.dist-info}/METADATA +5 -5
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev197.dist-info}/RECORD +36 -31
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev197.dist-info}/WHEEL +0 -0
- {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev197.dist-info}/entry_points.txt +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "2.9.0-dev.
|
|
1
|
+
__version__ = "2.9.0-dev.197"
|
|
@@ -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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
248
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
138
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
111
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
50
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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("robotframework")
|
|
56
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_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,
|
|
@@ -180,7 +181,7 @@ class RobotCompletionProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
180
181
|
config,
|
|
181
182
|
).collect(position, context)
|
|
182
183
|
|
|
183
|
-
@language_id("robotframework")
|
|
184
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
84
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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("robotframework")
|
|
88
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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("robotframework")
|
|
97
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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("robotframework")
|
|
104
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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 ("robotframework", MARKDOWN_LANGUAGE_ID):
|
|
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("robotframework")
|
|
131
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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("robotframework")
|
|
164
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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("robotframework")
|
|
223
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
29
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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,6 +10,7 @@ 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
|
)
|
|
@@ -69,11 +70,14 @@ class _Visitor(Visitor):
|
|
|
69
70
|
|
|
70
71
|
return finder.result if finder.result else None
|
|
71
72
|
|
|
73
|
+
def node_range(self, node: ast.AST) -> Range:
|
|
74
|
+
return range_from_node(node)
|
|
75
|
+
|
|
72
76
|
def visit_Section(self, node: Section) -> None: # noqa: N802
|
|
73
77
|
if not node.header or not node.header.name:
|
|
74
78
|
return
|
|
75
79
|
|
|
76
|
-
r =
|
|
80
|
+
r = self.node_range(node)
|
|
77
81
|
symbol = DocumentSymbol(
|
|
78
82
|
name=node.header.name,
|
|
79
83
|
kind=SymbolKind.MODULE,
|
|
@@ -91,7 +95,7 @@ class _Visitor(Visitor):
|
|
|
91
95
|
return
|
|
92
96
|
|
|
93
97
|
if self.current_symbol is not None and self.current_symbol.children is not None:
|
|
94
|
-
r =
|
|
98
|
+
r = self.node_range(node)
|
|
95
99
|
symbol = DocumentSymbol(
|
|
96
100
|
name=node.name,
|
|
97
101
|
kind=SymbolKind.CLASS,
|
|
@@ -108,7 +112,7 @@ class _Visitor(Visitor):
|
|
|
108
112
|
return
|
|
109
113
|
|
|
110
114
|
if self.current_symbol is not None and self.current_symbol.children is not None:
|
|
111
|
-
r =
|
|
115
|
+
r = self.node_range(node)
|
|
112
116
|
symbol = DocumentSymbol(
|
|
113
117
|
name=node.name,
|
|
114
118
|
kind=SymbolKind.FUNCTION,
|
|
@@ -270,6 +274,6 @@ class _Visitor(Visitor):
|
|
|
270
274
|
if node.tokens[:1]:
|
|
271
275
|
r = range_from_token(node.tokens[0])
|
|
272
276
|
else:
|
|
273
|
-
r =
|
|
277
|
+
r = self.node_range(node)
|
|
274
278
|
symbol = DocumentSymbol(name=name, kind=SymbolKind.VARIABLE, range=r, selection_range=r)
|
|
275
279
|
self.current_symbol.children.append(symbol)
|
|
@@ -50,7 +50,7 @@ class _Visitor(Visitor):
|
|
|
50
50
|
|
|
51
51
|
return finder.result if finder.result else None
|
|
52
52
|
|
|
53
|
-
def
|
|
53
|
+
def _append(self, start_node: ast.AST, kind: str, end_node: Optional[ast.AST] = None) -> None:
|
|
54
54
|
if end_node is None:
|
|
55
55
|
end_node = start_node
|
|
56
56
|
if not self.line_folding_only:
|
|
@@ -73,51 +73,51 @@ class _Visitor(Visitor):
|
|
|
73
73
|
)
|
|
74
74
|
|
|
75
75
|
def visit_Section(self, node: ast.AST) -> None: # noqa: N802
|
|
76
|
-
self.
|
|
76
|
+
self._append(node, kind="section")
|
|
77
77
|
|
|
78
78
|
self.generic_visit(node)
|
|
79
79
|
|
|
80
80
|
def visit_CommentSection(self, node: ast.AST) -> None: # noqa: N802
|
|
81
|
-
self.
|
|
81
|
+
self._append(node, kind="comment")
|
|
82
82
|
self.generic_visit(node)
|
|
83
83
|
|
|
84
84
|
def visit_Documentation(self, node: ast.AST) -> None: # noqa: N802
|
|
85
|
-
self.
|
|
85
|
+
self._append(node, kind="documentation")
|
|
86
86
|
self.generic_visit(node)
|
|
87
87
|
|
|
88
88
|
def visit_TestCase(self, node: TestCase) -> None: # noqa: N802
|
|
89
89
|
if node.name:
|
|
90
|
-
self.
|
|
90
|
+
self._append(node, kind="testcase")
|
|
91
91
|
self.generic_visit(node)
|
|
92
92
|
|
|
93
93
|
def visit_Keyword(self, node: Keyword) -> None: # noqa: N802
|
|
94
94
|
if node.name:
|
|
95
|
-
self.
|
|
95
|
+
self._append(node, kind="keyword")
|
|
96
96
|
self.generic_visit(node)
|
|
97
97
|
|
|
98
98
|
def visit_ForLoop(self, node: ast.AST) -> None: # noqa: N802
|
|
99
|
-
self.
|
|
99
|
+
self._append(node, kind="for_loop")
|
|
100
100
|
self.generic_visit(node)
|
|
101
101
|
|
|
102
102
|
def visit_Group(self, node: ast.AST) -> None: # noqa: N802
|
|
103
|
-
self.
|
|
103
|
+
self._append(node, kind="group")
|
|
104
104
|
self.generic_visit(node)
|
|
105
105
|
|
|
106
106
|
def visit_For(self, node: ast.AST) -> None: # noqa: N802
|
|
107
|
-
self.
|
|
107
|
+
self._append(node, kind="for")
|
|
108
108
|
self.generic_visit(node)
|
|
109
109
|
|
|
110
110
|
def visit_If(self, node: If) -> None: # noqa: N802
|
|
111
111
|
if node.orelse is not None and node.body[-1]:
|
|
112
|
-
self.
|
|
112
|
+
self._append(node, kind="if", end_node=node.body[-1])
|
|
113
113
|
elif node.orelse is None and node.type == "ELSE":
|
|
114
|
-
self.
|
|
114
|
+
self._append(
|
|
115
115
|
node,
|
|
116
116
|
kind="if",
|
|
117
117
|
end_node=self.current_if[-1] if self.current_if else None,
|
|
118
118
|
)
|
|
119
119
|
else:
|
|
120
|
-
self.
|
|
120
|
+
self._append(node, kind="if")
|
|
121
121
|
|
|
122
122
|
if node.type == "IF":
|
|
123
123
|
self.current_if.append(node)
|
|
@@ -128,11 +128,11 @@ class _Visitor(Visitor):
|
|
|
128
128
|
self.current_if.remove(node)
|
|
129
129
|
|
|
130
130
|
def visit_While(self, node: While) -> None: # noqa: N802
|
|
131
|
-
self.
|
|
131
|
+
self._append(node, kind="while")
|
|
132
132
|
self.generic_visit(node)
|
|
133
133
|
|
|
134
134
|
def visit_Try(self, node: Try) -> None: # noqa: N802
|
|
135
|
-
self.
|
|
135
|
+
self._append(node, kind="try", end_node=node.body[-1] if node.body else None)
|
|
136
136
|
self.generic_visit(node)
|
|
137
137
|
|
|
138
138
|
|
|
@@ -16,6 +16,8 @@ from ..configuration import RoboCopConfig
|
|
|
16
16
|
from .protocol_part import RobotLanguageServerProtocolPart
|
|
17
17
|
|
|
18
18
|
if TYPE_CHECKING:
|
|
19
|
+
from robocop.formatter.runner import RobocopFormatter
|
|
20
|
+
|
|
19
21
|
from ..protocol import RobotLanguageServerProtocol
|
|
20
22
|
|
|
21
23
|
|
|
@@ -78,7 +80,6 @@ class RobotFormattingProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
78
80
|
|
|
79
81
|
config_manager = self.parent.robocop_helper.get_config_manager(workspace_folder)
|
|
80
82
|
|
|
81
|
-
source = document.uri.to_path()
|
|
82
83
|
config = config_manager.get_config_for_source_file(document.uri.to_path())
|
|
83
84
|
|
|
84
85
|
if range is not None:
|
|
@@ -89,17 +90,8 @@ class RobotFormattingProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
89
90
|
runner = RobocopFormatter(config_manager)
|
|
90
91
|
runner.config = config
|
|
91
92
|
|
|
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():
|
|
93
|
+
new_text = self.formatted_text(runner, document, config)
|
|
94
|
+
if new_text == document.text():
|
|
103
95
|
return None
|
|
104
96
|
|
|
105
97
|
return [
|
|
@@ -108,10 +100,23 @@ class RobotFormattingProtocolPart(RobotLanguageServerProtocolPart):
|
|
|
108
100
|
start=Position(line=0, character=0),
|
|
109
101
|
end=Position(line=len(document.get_lines()), character=0),
|
|
110
102
|
),
|
|
111
|
-
new_text=
|
|
103
|
+
new_text=new_text,
|
|
112
104
|
)
|
|
113
105
|
]
|
|
114
106
|
|
|
107
|
+
def formatted_text(self, runner: "RobocopFormatter", document: TextDocument, config: Any) -> str:
|
|
108
|
+
model = self.parent.documents_cache.get_uncached_model(document)
|
|
109
|
+
if self.parent.robocop_helper.robocop_version >= (8, 0):
|
|
110
|
+
from robocop.source_file import SourceFile
|
|
111
|
+
|
|
112
|
+
# overwrite _model to stop Robocop from loading it
|
|
113
|
+
source_file = SourceFile(path=document.uri.to_path(), config=config, _model=model)
|
|
114
|
+
_, _, new, _ = runner.format_until_stable(source_file)
|
|
115
|
+
else:
|
|
116
|
+
_, _, new, _ = runner.format_until_stable(model)
|
|
117
|
+
|
|
118
|
+
return str(new.text)
|
|
119
|
+
|
|
115
120
|
@language_id("robotframework")
|
|
116
121
|
def format_range(
|
|
117
122
|
self,
|
|
@@ -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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
29
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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("robotframework")
|
|
36
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
91
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
76
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
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.document_formats import MARKDOWN_LANGUAGE_ID
|
|
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("robotframework")
|
|
48
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
48
49
|
@_logger.call
|
|
49
50
|
def collect(
|
|
50
51
|
self,
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Any, List, Optional, Union
|
|
2
|
+
|
|
3
|
+
from robotcode.core.language import language_id
|
|
4
|
+
from robotcode.core.lsp.types import CompletionContext, CompletionItem, CompletionList, Position
|
|
5
|
+
from robotcode.core.text_document import TextDocument
|
|
6
|
+
from robotcode.robot.document_formats import MARKDOWN_LANGUAGE_ID
|
|
7
|
+
from robotcode.robot.utils.markdown_blocks import find_block
|
|
8
|
+
|
|
9
|
+
from ..protocol_part import RobotLanguageServerProtocolPart
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from ...protocol import RobotLanguageServerProtocol
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MarkdownCompletionProtocolPart(RobotLanguageServerProtocolPart):
|
|
16
|
+
"""Completion in a Markdown document: Robot Framework's completion, on the lines of the code blocks only."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, parent: "RobotLanguageServerProtocol") -> None:
|
|
19
|
+
super().__init__(parent)
|
|
20
|
+
|
|
21
|
+
parent.completion.collect.add(self.collect)
|
|
22
|
+
|
|
23
|
+
@language_id(MARKDOWN_LANGUAGE_ID)
|
|
24
|
+
def collect(
|
|
25
|
+
self,
|
|
26
|
+
sender: Any,
|
|
27
|
+
document: TextDocument,
|
|
28
|
+
position: Position,
|
|
29
|
+
context: Optional[CompletionContext],
|
|
30
|
+
) -> Union[List[CompletionItem], CompletionList, None]:
|
|
31
|
+
if find_block(self.parent.documents_cache.get_markdown_blocks(document), position.line) is None:
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
return self.parent.robot_completion.collect(sender, document, position, context)
|