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.
Files changed (36) hide show
  1. robotcode/language_server/__version__.py +1 -1
  2. robotcode/language_server/common/parts/documents.py +7 -5
  3. robotcode/language_server/common/protocol.py +3 -3
  4. robotcode/language_server/robotframework/parts/code_action_documentation.py +2 -1
  5. robotcode/language_server/robotframework/parts/code_action_helper_mixin.py +21 -2
  6. robotcode/language_server/robotframework/parts/code_action_quick_fixes.py +6 -3
  7. robotcode/language_server/robotframework/parts/code_action_refactor.py +2 -1
  8. robotcode/language_server/robotframework/parts/code_lens.py +3 -2
  9. robotcode/language_server/robotframework/parts/completion.py +4 -3
  10. robotcode/language_server/robotframework/parts/diagnostics.py +9 -8
  11. robotcode/language_server/robotframework/parts/document_highlight.py +2 -1
  12. robotcode/language_server/robotframework/parts/document_symbols.py +10 -5
  13. robotcode/language_server/robotframework/parts/folding_range.py +16 -15
  14. robotcode/language_server/robotframework/parts/formatting.py +21 -15
  15. robotcode/language_server/robotframework/parts/goto.py +3 -2
  16. robotcode/language_server/robotframework/parts/hover.py +2 -1
  17. robotcode/language_server/robotframework/parts/inlay_hint.py +2 -1
  18. robotcode/language_server/robotframework/parts/inline_value.py +2 -1
  19. robotcode/language_server/robotframework/parts/markdown/__init__.py +0 -0
  20. robotcode/language_server/robotframework/parts/markdown/completion.py +34 -0
  21. robotcode/language_server/robotframework/parts/markdown/placement.py +49 -0
  22. robotcode/language_server/robotframework/parts/markdown/ranges.py +86 -0
  23. robotcode/language_server/robotframework/parts/markdown/robocop.py +82 -0
  24. robotcode/language_server/robotframework/parts/references.py +6 -5
  25. robotcode/language_server/robotframework/parts/rename.py +3 -2
  26. robotcode/language_server/robotframework/parts/robocop_diagnostics.py +17 -13
  27. robotcode/language_server/robotframework/parts/robot_workspace.py +10 -7
  28. robotcode/language_server/robotframework/parts/selection_range.py +10 -3
  29. robotcode/language_server/robotframework/parts/semantic_tokens.py +5 -4
  30. robotcode/language_server/robotframework/parts/signature_help.py +2 -1
  31. robotcode/language_server/robotframework/parts/workspace_symbols.py +2 -1
  32. robotcode/language_server/robotframework/protocol.py +33 -17
  33. {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/METADATA +5 -5
  34. {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/RECORD +36 -31
  35. {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/WHEEL +0 -0
  36. {robotcode_language_server-2.9.0.dev186.dist-info → robotcode_language_server-2.9.0.dev214.dist-info}/entry_points.txt +0 -0
@@ -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.language_definitions 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)
@@ -0,0 +1,49 @@
1
+ from typing import TYPE_CHECKING, Any, Optional, Tuple
2
+
3
+ from robotcode.core.language import language_id
4
+ from robotcode.core.lsp.types import Position, Range
5
+ from robotcode.core.text_document import TextDocument
6
+ from robotcode.robot.language_definitions import MARKDOWN_LANGUAGE_ID
7
+ from robotcode.robot.utils.markdown_blocks import find_block, indent_for_block
8
+
9
+ from ..protocol_part import RobotLanguageServerProtocolPart
10
+
11
+ if TYPE_CHECKING:
12
+ from ...protocol import RobotLanguageServerProtocol
13
+
14
+
15
+ class MarkdownCodePlacementProtocolPart(RobotLanguageServerProtocolPart):
16
+ """Places the code of code actions in a Markdown document inside its code blocks."""
17
+
18
+ def __init__(self, parent: "RobotLanguageServerProtocol") -> None:
19
+ super().__init__(parent)
20
+
21
+ parent.place_code.add(self.place_code)
22
+
23
+ @language_id(MARKDOWN_LANGUAGE_ID)
24
+ def place_code(self, sender: Any, document: TextDocument, text: str, range: Range) -> Optional[Tuple[str, Range]]:
25
+ blocks = self.parent.documents_cache.get_markdown_blocks(document)
26
+ if not blocks:
27
+ return None
28
+
29
+ line = range.start.line
30
+ block = find_block(blocks, line)
31
+ if block is not None:
32
+ return indent_for_block(text, block), range
33
+
34
+ # a position after a block goes to the end of that block, a position before the first block to its start
35
+ before = [(b.closing_fence, b) for b in blocks if b.closing_fence is not None and b.closing_fence <= line]
36
+ if before:
37
+ fence, block = before[-1]
38
+ position = Position(fence, 0)
39
+ else:
40
+ block = blocks[0]
41
+ position = Position(block.opening_fence + 1, 0)
42
+
43
+ # Robot Framework breaks the line it inserts at the end of; the new position starts a line
44
+ if range.start.character > 0 and text.startswith("\n"):
45
+ text = text[1:]
46
+ if not text.endswith("\n"):
47
+ text += "\n"
48
+
49
+ return indent_for_block(text, block), Range(position, position)
@@ -0,0 +1,86 @@
1
+ """Folding, symbol and selection ranges of a Markdown document, which stay inside its code blocks."""
2
+
3
+ import ast
4
+ from itertools import takewhile
5
+ from typing import Any, List, Optional, Sequence, Union
6
+
7
+ from robotcode.core.language import language_id
8
+ from robotcode.core.lsp.types import DocumentSymbol, FoldingRange, Position, Range, SelectionRange, SymbolInformation
9
+ from robotcode.core.text_document import TextDocument
10
+ from robotcode.robot.language_definitions import MARKDOWN_LANGUAGE_ID
11
+ from robotcode.robot.utils.ast import range_from_node
12
+ from robotcode.robot.utils.markdown_blocks import RobotBlock, find_block, range_in_blocks
13
+
14
+ from ..document_symbols import RobotDocumentSymbolsProtocolPart
15
+ from ..document_symbols import _Visitor as _RobotSymbolsVisitor
16
+ from ..folding_range import RobotFoldingRangeProtocolPart
17
+ from ..folding_range import _Visitor as _RobotFoldingVisitor
18
+ from ..selection_range import RobotSelectionRangeProtocolPart
19
+
20
+
21
+ class _FoldingVisitor(_RobotFoldingVisitor):
22
+ def __init__(self, parent: RobotFoldingRangeProtocolPart, blocks: Sequence[RobotBlock]) -> None:
23
+ super().__init__(parent)
24
+ self.blocks = blocks
25
+
26
+ def _append(self, start_node: ast.AST, kind: str, end_node: Optional[ast.AST] = None) -> None:
27
+ start = range_in_blocks(start_node, self.blocks)
28
+ end = range_in_blocks(end_node if end_node is not None else start_node, self.blocks)
29
+ if start is None or end is None:
30
+ return
31
+
32
+ self.result.append(
33
+ FoldingRange(
34
+ start_line=start.start.line,
35
+ end_line=end.end.line,
36
+ start_character=None if self.line_folding_only else start.start.character,
37
+ end_character=None if self.line_folding_only else end.end.character,
38
+ kind=kind,
39
+ )
40
+ )
41
+
42
+
43
+ class MarkdownFoldingRangeProtocolPart(RobotFoldingRangeProtocolPart):
44
+ @language_id(MARKDOWN_LANGUAGE_ID)
45
+ def collect(self, sender: Any, document: TextDocument) -> Optional[List[FoldingRange]]:
46
+ visitor = _FoldingVisitor(self, self.parent.documents_cache.get_markdown_blocks(document))
47
+ visitor.visit(self.parent.documents_cache.get_model(document))
48
+ return visitor.result or None
49
+
50
+
51
+ class _SymbolsVisitor(_RobotSymbolsVisitor):
52
+ def __init__(self, parent: RobotDocumentSymbolsProtocolPart, blocks: Sequence[RobotBlock]) -> None:
53
+ super().__init__(parent)
54
+ self.blocks = blocks
55
+
56
+ def node_range(self, node: ast.AST) -> Range:
57
+ # the nodes with symbols, sections, tests and keywords, have their name in a block
58
+ return range_in_blocks(node, self.blocks) or range_from_node(node)
59
+
60
+
61
+ class MarkdownDocumentSymbolsProtocolPart(RobotDocumentSymbolsProtocolPart):
62
+ @language_id(MARKDOWN_LANGUAGE_ID)
63
+ def collect(
64
+ self, sender: Any, document: TextDocument
65
+ ) -> Optional[Union[List[DocumentSymbol], List[SymbolInformation], None]]:
66
+ visitor = _SymbolsVisitor(self, self.parent.documents_cache.get_markdown_blocks(document))
67
+ visitor.visit(self.parent.documents_cache.get_model(document))
68
+ return visitor.result or None
69
+
70
+
71
+ class MarkdownSelectionRangeProtocolPart(RobotSelectionRangeProtocolPart):
72
+ @language_id(MARKDOWN_LANGUAGE_ID)
73
+ def collect(self, sender: Any, document: TextDocument, positions: List[Position]) -> Optional[List[SelectionRange]]:
74
+ blocks = self.parent.documents_cache.get_markdown_blocks(document)
75
+
76
+ # a position outside the code blocks ends the result, like one without a node
77
+ return super().collect(
78
+ sender, document, list(takewhile(lambda p: find_block(blocks, p.line) is not None, positions))
79
+ )
80
+
81
+ def node_range(self, document: TextDocument, node: ast.AST, position: Position) -> Optional[Range]:
82
+ # a node whose range ends before the position, in an earlier block, has no range there
83
+ node_range = range_in_blocks(node, self.parent.documents_cache.get_markdown_blocks(document))
84
+ if node_range is None or not position.is_in_range(node_range, True):
85
+ return None
86
+ return node_range
@@ -0,0 +1,82 @@
1
+ """Robocop's checks and formatting of a Markdown document, with Robocop's own support for Markdown files."""
2
+
3
+ from typing import TYPE_CHECKING, Any, List, Optional
4
+
5
+ from robotcode.core.language import language_id
6
+ from robotcode.core.lsp.types import FormattingOptions, MessageType, Range, TextEdit
7
+ from robotcode.core.text_document import TextDocument
8
+ from robotcode.robot.language_definitions import MARKDOWN_LANGUAGE_ID
9
+
10
+ from ....common.parts.diagnostics import DiagnosticsCollectType, DiagnosticsResult
11
+ from ..formatting import RobotFormattingProtocolPart
12
+ from ..robocop_diagnostics import RobotRoboCopDiagnosticsProtocolPart
13
+
14
+ if TYPE_CHECKING:
15
+ from robocop.formatter.runner import RobocopFormatter
16
+ from robocop.linter.runner import RobocopLinter
17
+
18
+ # Robocop reads the code blocks of Markdown files itself since 9.2
19
+ ROBOCOP_MARKDOWN_VERSION = (9, 2)
20
+
21
+
22
+ def _source_file(document: TextDocument, config: Any) -> Any:
23
+ # Robocop's source file of a Markdown document, from the current text of the document
24
+ from robocop.source_file import EmbeddedSourceFile
25
+
26
+ source_file = EmbeddedSourceFile(
27
+ path=document.uri.to_path(), config=config, _source_lines=document.text().splitlines(keepends=True)
28
+ )
29
+ # builds the models of the code blocks from the given lines, not from the file on disk
30
+ source_file.reload_model()
31
+ return source_file
32
+
33
+
34
+ class MarkdownRoboCopDiagnosticsProtocolPart(RobotRoboCopDiagnosticsProtocolPart):
35
+ @language_id(MARKDOWN_LANGUAGE_ID)
36
+ def collect_diagnostics(
37
+ self, sender: Any, document: TextDocument, diagnostics_type: DiagnosticsCollectType
38
+ ) -> Optional[DiagnosticsResult]:
39
+ if self.parent.robocop_helper.robocop_version < ROBOCOP_MARKDOWN_VERSION:
40
+ return None
41
+
42
+ return super().collect_diagnostics(sender, document, diagnostics_type)
43
+
44
+ def run_check(self, linter: "RobocopLinter", document: TextDocument, config: Any) -> Any:
45
+ return linter.run_check(_source_file(document, config))
46
+
47
+
48
+ class MarkdownFormattingProtocolPart(RobotFormattingProtocolPart):
49
+ @language_id(MARKDOWN_LANGUAGE_ID)
50
+ def format(
51
+ self,
52
+ sender: Any,
53
+ document: TextDocument,
54
+ options: FormattingOptions,
55
+ **further_options: Any,
56
+ ) -> Optional[List[TextEdit]]:
57
+ helper = self.parent.robocop_helper
58
+ if not helper.robocop_installed or helper.robocop_version < ROBOCOP_MARKDOWN_VERSION:
59
+ self.parent.window.show_message(
60
+ "Formatting Markdown files needs 'robotframework-robocop' 9.2 or newer.", MessageType.ERROR
61
+ )
62
+ return None
63
+
64
+ return self.format_robocop(document, options, **further_options)
65
+
66
+ @language_id(MARKDOWN_LANGUAGE_ID)
67
+ def format_range(
68
+ self,
69
+ sender: Any,
70
+ document: TextDocument,
71
+ range: Range,
72
+ options: FormattingOptions,
73
+ **further_options: Any,
74
+ ) -> Optional[List[TextEdit]]:
75
+ # TODO: pass the range on like for `.robot` files once Robocop's `format_embedded` turns `start_line`/`end_line`
76
+ # into the lines of each block (MarketSquare/robotframework-robocop#1984); up to 9.4.0 it applies them to the
77
+ # block-local lines of every block
78
+ return None
79
+
80
+ def formatted_text(self, runner: "RobocopFormatter", document: TextDocument, config: Any) -> str:
81
+ _, _, new_text = runner.format_embedded(_source_file(document, config))
82
+ return str(new_text)
@@ -35,6 +35,7 @@ from robotcode.robot.diagnostics.library_doc import (
35
35
  LibraryDoc,
36
36
  )
37
37
  from robotcode.robot.diagnostics.namespace import Namespace
38
+ from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
38
39
  from robotcode.robot.utils import RF_VERSION
39
40
  from robotcode.robot.utils.ast import (
40
41
  get_nodes_at_position,
@@ -86,15 +87,15 @@ class RobotReferencesProtocolPart(RobotLanguageServerProtocolPart):
86
87
  def do_on_file_changed(self, sender: Any, files: List[FileEvent]) -> None:
87
88
  self.clear_cache()
88
89
 
89
- @language_id("robotframework")
90
+ @language_id(*ROBOT_LANGUAGE_IDS)
90
91
  def document_did_change(self, sender: Any, document: TextDocument) -> None:
91
92
  self.clear_cache()
92
93
 
93
- @language_id("robotframework")
94
+ @language_id(*ROBOT_LANGUAGE_IDS)
94
95
  def namespace_invalidated(self, sender: Any, namespace: Namespace) -> None:
95
96
  self.clear_cache()
96
97
 
97
- @language_id("robotframework")
98
+ @language_id(*ROBOT_LANGUAGE_IDS)
98
99
  def namespace_initialized(self, sender: Any, namespace: Namespace) -> None:
99
100
  # the new analysis changed the index, so a result found before it can miss its references
100
101
  self.clear_cache()
@@ -122,7 +123,7 @@ class RobotReferencesProtocolPart(RobotLanguageServerProtocolPart):
122
123
  return method
123
124
  return None
124
125
 
125
- @language_id("robotframework")
126
+ @language_id(*ROBOT_LANGUAGE_IDS)
126
127
  @_logger.call
127
128
  def collect(
128
129
  self,
@@ -192,7 +193,7 @@ class RobotReferencesProtocolPart(RobotLanguageServerProtocolPart):
192
193
  ) -> List[Location]:
193
194
  result: List[Location] = []
194
195
 
195
- for doc in filter(lambda d: d.language_id == "robotframework", self.parent.documents.documents):
196
+ for doc in filter(lambda d: d.language_id in ROBOT_LANGUAGE_IDS, self.parent.documents.documents):
196
197
  check_current_task_canceled()
197
198
 
198
199
  result.extend(func(doc, *args, **kwargs))
@@ -33,6 +33,7 @@ from robotcode.robot.diagnostics.entities import (
33
33
  VariableDefinitionType,
34
34
  )
35
35
  from robotcode.robot.diagnostics.library_doc import KeywordDoc
36
+ from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
36
37
 
37
38
  from ...common.parts.rename import CantRenameError
38
39
  from .protocol_part import RobotLanguageServerProtocolPart
@@ -56,7 +57,7 @@ class RobotRenameProtocolPart(RobotLanguageServerProtocolPart):
56
57
  parent.rename.collect.add(self.collect)
57
58
  parent.rename.collect_prepare.add(self.collect_prepare)
58
59
 
59
- @language_id("robotframework")
60
+ @language_id(*ROBOT_LANGUAGE_IDS)
60
61
  @_logger.call
61
62
  def collect(
62
63
  self, sender: Any, document: TextDocument, position: Position, new_name: str
@@ -71,7 +72,7 @@ class RobotRenameProtocolPart(RobotLanguageServerProtocolPart):
71
72
 
72
73
  return None
73
74
 
74
- @language_id("robotframework")
75
+ @language_id(*ROBOT_LANGUAGE_IDS)
75
76
  @_logger.call
76
77
  def collect_prepare(self, sender: Any, document: TextDocument, position: Position) -> Optional[PrepareRenameResult]:
77
78
  result = self._prepare_rename_variable(document, position)
@@ -14,6 +14,7 @@ from robotcode.core.text_document import TextDocument
14
14
  from robotcode.core.utils.logging import LoggingDescriptor
15
15
  from robotcode.core.utils.version import Version, create_version_from_str
16
16
  from robotcode.core.workspace import WorkspaceFolder
17
+ from robotcode.robot.language_definitions import ROBOTFRAMEWORK_LANGUAGE_ID
17
18
 
18
19
  from ...common.parts.diagnostics import DiagnosticsCollectType, DiagnosticsResult
19
20
  from ..configuration import RoboCopConfig
@@ -55,7 +56,7 @@ class RobotRoboCopDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
55
56
  self._robocop_linters[workspace_folder] = linter
56
57
  return linter
57
58
 
58
- @language_id("robotframework")
59
+ @language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
59
60
  @_logger.call
60
61
  def collect_diagnostics(
61
62
  self, sender: Any, document: TextDocument, diagnostics_type: DiagnosticsCollectType
@@ -83,18 +84,8 @@ class RobotRoboCopDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
83
84
 
84
85
  linter = self.get_linter(workspace_folder)
85
86
 
86
- source = document.uri.to_path()
87
- config = linter.config_manager.get_config_for_source_file(source)
88
- model = self.parent.documents_cache.get_model(document)
89
-
90
- if self.parent.robocop_helper.robocop_version >= (8, 0):
91
- from robocop.source_file import SourceFile
92
-
93
- # overwrite _model to stop Robocop from loading it
94
- source_file = SourceFile(path=source, config=config, _model=model)
95
- diagnostics = linter.run_check(source_file)
96
- else:
97
- diagnostics = linter.run_check(model, source, config)
87
+ config = linter.config_manager.get_config_for_source_file(document.uri.to_path())
88
+ diagnostics = self.run_check(linter, document, config)
98
89
 
99
90
  return [
100
91
  Diagnostic(
@@ -129,6 +120,19 @@ class RobotRoboCopDiagnosticsProtocolPart(RobotLanguageServerProtocolPart):
129
120
  for diagnostic in diagnostics
130
121
  ]
131
122
 
123
+ def run_check(self, linter: "RobocopLinter", document: TextDocument, config: Any) -> Any:
124
+ source = document.uri.to_path()
125
+ model = self.parent.documents_cache.get_model(document)
126
+
127
+ if self.parent.robocop_helper.robocop_version >= (8, 0):
128
+ from robocop.source_file import SourceFile
129
+
130
+ # overwrite _model to stop Robocop from loading it
131
+ source_file = SourceFile(path=source, config=config, _model=model)
132
+ return linter.run_check(source_file)
133
+
134
+ return linter.run_check(model, source, config)
135
+
132
136
  @_logger.call
133
137
  def collect_old(
134
138
  self,
@@ -34,6 +34,7 @@ from robotcode.robot.diagnostics.library_doc import (
34
34
  RESOURCE_FILE_EXTENSION,
35
35
  ROBOT_FILE_EXTENSION,
36
36
  )
37
+ from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
37
38
 
38
39
  from ..configuration import RobotCodeConfig
39
40
 
@@ -69,10 +70,9 @@ class RobotWorkspaceProtocolPart(RobotLanguageServerProtocolPart):
69
70
  def _on_initialized(self, sender: Any) -> None:
70
71
  # the workspace exists only after the initialize request, the parts of the protocol already before it
71
72
  self.parent.workspace.did_change_configuration.add(self._on_did_change_configuration)
73
+ extensions = sorted({e[1:] for d in self.parent.language_definitions for e in d.extensions})
72
74
  self.parent.workspace.add_file_watcher(
73
- self._on_files_deleted,
74
- f"**/*.{{{ROBOT_FILE_EXTENSION[1:]},{RESOURCE_FILE_EXTENSION[1:]}}}",
75
- WatchKind.DELETE,
75
+ self._on_files_deleted, f"**/*.{{{','.join(extensions)}}}", WatchKind.DELETE
76
76
  )
77
77
 
78
78
  def _on_files_deleted(self, sender: Any, changes: List[FileEvent]) -> None:
@@ -86,10 +86,10 @@ class RobotWorkspaceProtocolPart(RobotLanguageServerProtocolPart):
86
86
 
87
87
  path = uri.to_path()
88
88
  # the cache keeps the entries of a file that is there again
89
- if path.suffix in WORKSPACE_FILE_EXTENSIONS and not path.exists():
89
+ if self._has_workspace_extension(path) and not path.exists():
90
90
  self.parent.documents_cache.remove_cached_analysis(path)
91
91
 
92
- @language_id("robotframework")
92
+ @language_id(*ROBOT_LANGUAGE_IDS)
93
93
  def on_read_document_text(self, sender: Any, uri: Uri) -> Optional[str]:
94
94
  from robot.utils import FileReader
95
95
 
@@ -112,6 +112,9 @@ class RobotWorkspaceProtocolPart(RobotLanguageServerProtocolPart):
112
112
  ]
113
113
  return IgnoreSpec.from_list([*DEFAULT_SPEC_RULES, *exclude_patterns], folder.uri.to_path())
114
114
 
115
+ def _has_workspace_extension(self, path: Path) -> bool:
116
+ return path.suffix in WORKSPACE_FILE_EXTENSIONS or self.parent.documents.detect_language_id(path) != "unknown"
117
+
115
118
  def collect_workspace_files(self, folder: WorkspaceFolder) -> List[Path]:
116
119
  """The Robot Framework files of a workspace folder, without the excluded and ignored ones."""
117
120
  return [
@@ -124,12 +127,12 @@ class RobotWorkspaceProtocolPart(RobotLanguageServerProtocolPart):
124
127
  verbose_callback=self._logger.debug,
125
128
  verbose_trace=False,
126
129
  )
127
- if f.suffix in WORKSPACE_FILE_EXTENSIONS
130
+ if self._has_workspace_extension(f)
128
131
  ]
129
132
 
130
133
  def is_workspace_file(self, folder: WorkspaceFolder, path: Path) -> bool:
131
134
  """Whether `collect_workspace_files` would return `path`."""
132
- return path.suffix in WORKSPACE_FILE_EXTENSIONS and iter_files_includes(
135
+ return self._has_workspace_extension(path) and iter_files_includes(
133
136
  path,
134
137
  folder.uri.to_path(),
135
138
  ignore_files=WORKSPACE_IGNORE_FILES,
@@ -1,12 +1,14 @@
1
+ import ast
1
2
  from typing import TYPE_CHECKING, Any, List, Optional
2
3
 
3
4
  from robot.parsing.model.statements import Statement
4
5
 
5
6
  from robotcode.core.language import language_id
6
- from robotcode.core.lsp.types import Position, SelectionRange
7
+ from robotcode.core.lsp.types import Position, Range, SelectionRange
7
8
  from robotcode.core.text_document import TextDocument
8
9
  from robotcode.core.utils.logging import LoggingDescriptor
9
10
  from robotcode.robot.diagnostics.model_helper import ModelHelper
11
+ from robotcode.robot.language_definitions import ROBOTFRAMEWORK_LANGUAGE_ID
10
12
  from robotcode.robot.utils.ast import (
11
13
  get_nodes_at_position,
12
14
  get_tokens_at_position,
@@ -29,7 +31,10 @@ class RobotSelectionRangeProtocolPart(RobotLanguageServerProtocolPart):
29
31
 
30
32
  parent.selection_range.collect.add(self.collect)
31
33
 
32
- @language_id("robotframework")
34
+ def node_range(self, document: TextDocument, node: ast.AST, position: Position) -> Optional[Range]:
35
+ return range_from_node(node)
36
+
37
+ @language_id(ROBOTFRAMEWORK_LANGUAGE_ID)
33
38
  @_logger.call
34
39
  def collect(self, sender: Any, document: TextDocument, positions: List[Position]) -> Optional[List[SelectionRange]]:
35
40
  namespace = self.parent.documents_cache.get_namespace(document)
@@ -45,7 +50,9 @@ class RobotSelectionRangeProtocolPart(RobotLanguageServerProtocolPart):
45
50
 
46
51
  current_range: Optional[SelectionRange] = None
47
52
  for n in nodes:
48
- current_range = SelectionRange(range_from_node(n), current_range)
53
+ node_range = self.node_range(document, n, position)
54
+ if node_range is not None:
55
+ current_range = SelectionRange(node_range, current_range)
49
56
 
50
57
  if current_range is not None:
51
58
  node = nodes[-1]
@@ -76,6 +76,7 @@ from robotcode.robot.diagnostics.semantic_analyzer.nodes import (
76
76
  SemanticToken,
77
77
  )
78
78
  from robotcode.robot.diagnostics.semantic_analyzer.variable_tokenizer import VariableSite, build_variable_sub_tokens
79
+ from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
79
80
  from robotcode.robot.utils import RF_VERSION
80
81
  from robotcode.robot.utils.ast import (
81
82
  cached_isinstance,
@@ -2075,7 +2076,7 @@ class RobotSemanticTokenProtocolPart(RobotLanguageServerProtocolPart):
2075
2076
  def _on_initialized(self, sender: Any) -> None:
2076
2077
  self.parent.documents_cache.namespace_invalidated.add(self.namespace_invalidated)
2077
2078
 
2078
- @language_id("robotframework")
2079
+ @language_id(*ROBOT_LANGUAGE_IDS)
2079
2080
  def namespace_invalidated(self, sender: Any, namespace: Namespace) -> None:
2080
2081
  if namespace.document is not None and namespace.document.opened_in_editor:
2081
2082
  self.parent.semantic_tokens.refresh()
@@ -2126,19 +2127,19 @@ class RobotSemanticTokenProtocolPart(RobotLanguageServerProtocolPart):
2126
2127
  self.parent.semantic_tokens.token_modifiers,
2127
2128
  )
2128
2129
 
2129
- @language_id("robotframework")
2130
+ @language_id(*ROBOT_LANGUAGE_IDS)
2130
2131
  def collect_full(
2131
2132
  self, sender: Any, document: TextDocument, **kwargs: Any
2132
2133
  ) -> Union[SemanticTokens, SemanticTokensPartialResult, None]:
2133
2134
  return self._collect(document, None)
2134
2135
 
2135
- @language_id("robotframework")
2136
+ @language_id(*ROBOT_LANGUAGE_IDS)
2136
2137
  def collect_range(
2137
2138
  self, sender: Any, document: TextDocument, range: Range, **kwargs: Any
2138
2139
  ) -> Union[SemanticTokens, SemanticTokensPartialResult, None]:
2139
2140
  return self._collect(document, range)
2140
2141
 
2141
- @language_id("robotframework")
2142
+ @language_id(*ROBOT_LANGUAGE_IDS)
2142
2143
  def collect_full_delta(
2143
2144
  self,
2144
2145
  sender: Any,
@@ -43,6 +43,7 @@ from robotcode.robot.diagnostics.semantic_analyzer.nodes import (
43
43
  SemanticStatement,
44
44
  SemanticToken,
45
45
  )
46
+ from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
46
47
  from robotcode.robot.utils.ast import (
47
48
  get_node_at_position,
48
49
  get_tokens_at_position,
@@ -414,7 +415,7 @@ class RobotSignatureHelpProtocolPart(RobotLanguageServerProtocolPart, ModelHelpe
414
415
  return method
415
416
  return None
416
417
 
417
- @language_id("robotframework")
418
+ @language_id(*ROBOT_LANGUAGE_IDS)
418
419
  @trigger_characters([" ", "\t"])
419
420
  @retrigger_characters([" ", "\t"])
420
421
  @_logger.call
@@ -8,6 +8,7 @@ from robotcode.core.lsp.types import (
8
8
  WorkspaceSymbol,
9
9
  )
10
10
  from robotcode.core.utils.logging import LoggingDescriptor
11
+ from robotcode.robot.language_definitions import ROBOT_LANGUAGE_IDS
11
12
 
12
13
  from .protocol_part import RobotLanguageServerProtocolPart
13
14
 
@@ -32,7 +33,7 @@ class RobotWorkspaceSymbolsProtocolPart(RobotLanguageServerProtocolPart):
32
33
  def collect(self, sender: Any, query: str) -> Optional[Union[List[WorkspaceSymbol], List[SymbolInformation], None]]:
33
34
  result: List[WorkspaceSymbol] = []
34
35
  for document in self.parent.documents.documents:
35
- if document.language_id == "robotframework":
36
+ if document.language_id in ROBOT_LANGUAGE_IDS:
36
37
  namespace = self.parent.documents_cache.get_only_initialized_namespace(document)
37
38
  if namespace is not None:
38
39
  container_name = namespace.library_doc.name
@@ -6,16 +6,18 @@ from pathlib import Path
6
6
  from typing import (
7
7
  TYPE_CHECKING,
8
8
  Any,
9
- ClassVar,
10
9
  Dict,
11
10
  Final,
12
11
  List,
13
12
  Optional,
13
+ Set,
14
+ Tuple,
14
15
  )
15
16
 
16
17
  from robotcode.core.event import event
17
18
  from robotcode.core.language import LanguageDefinition
18
- from robotcode.core.lsp.types import InitializeError, MessageType
19
+ from robotcode.core.lsp.types import InitializeError, MessageType, Range
20
+ from robotcode.core.text_document import TextDocument
19
21
  from robotcode.core.utils.dataclasses import CamelSnakeMixin, from_dict
20
22
  from robotcode.core.utils.logging import LoggingDescriptor
21
23
  from robotcode.jsonrpc2.protocol import JsonRPCErrorException, JsonRPCErrors, ProtocolPartDescriptor
@@ -23,6 +25,7 @@ from robotcode.language_server.common.parts.document_symbols import symbol_infor
23
25
  from robotcode.language_server.common.protocol import LanguageServerProtocol
24
26
  from robotcode.robot.config.model import RobotBaseProfile
25
27
  from robotcode.robot.diagnostics.workspace_config import RobotConfig, WorkspaceAnalysisConfig
28
+ from robotcode.robot.language_definitions import ROBOTFRAMEWORK_LANGUAGE, markdown_language_definition
26
29
  from robotcode.robot.utils import RF_VERSION
27
30
 
28
31
  from ..__version__ import __version__
@@ -45,6 +48,14 @@ from .parts.http_server import HttpServerProtocolPart
45
48
  from .parts.inlay_hint import RobotInlayHintProtocolPart
46
49
  from .parts.inline_value import RobotInlineValueProtocolPart
47
50
  from .parts.keywords_treeview import RobotKeywordsTreeViewPart
51
+ from .parts.markdown.completion import MarkdownCompletionProtocolPart
52
+ from .parts.markdown.placement import MarkdownCodePlacementProtocolPart
53
+ from .parts.markdown.ranges import (
54
+ MarkdownDocumentSymbolsProtocolPart,
55
+ MarkdownFoldingRangeProtocolPart,
56
+ MarkdownSelectionRangeProtocolPart,
57
+ )
58
+ from .parts.markdown.robocop import MarkdownFormattingProtocolPart, MarkdownRoboCopDiagnosticsProtocolPart
48
59
  from .parts.project_info import ProjectInfoPart
49
60
  from .parts.references import RobotReferencesProtocolPart
50
61
  from .parts.rename import RobotRenameProtocolPart
@@ -120,6 +131,14 @@ class RobotLanguageServerProtocol(LanguageServerProtocol):
120
131
  robot_code_action_quick_fixes = ProtocolPartDescriptor(RobotCodeActionQuickFixesProtocolPart)
121
132
  robot_code_action_refactor = ProtocolPartDescriptor(RobotCodeActionRefactorProtocolPart)
122
133
 
134
+ markdown_completion = ProtocolPartDescriptor(MarkdownCompletionProtocolPart)
135
+ markdown_folding_ranges = ProtocolPartDescriptor(MarkdownFoldingRangeProtocolPart)
136
+ markdown_document_symbols = ProtocolPartDescriptor(MarkdownDocumentSymbolsProtocolPart)
137
+ markdown_selection_range = ProtocolPartDescriptor(MarkdownSelectionRangeProtocolPart)
138
+ markdown_code_placement = ProtocolPartDescriptor(MarkdownCodePlacementProtocolPart)
139
+ markdown_robocop_diagnostics = ProtocolPartDescriptor(MarkdownRoboCopDiagnosticsProtocolPart)
140
+ markdown_formatting = ProtocolPartDescriptor(MarkdownFormattingProtocolPart)
141
+
123
142
  robot_debugging_utils = ProtocolPartDescriptor(RobotDebuggingUtilsProtocolPart)
124
143
  robot_keywords_treeview = ProtocolPartDescriptor(RobotKeywordsTreeViewPart)
125
144
  robot_documentation_viewer = ProtocolPartDescriptor(RobotDocumentationViewerPart)
@@ -132,7 +151,7 @@ class RobotLanguageServerProtocol(LanguageServerProtocol):
132
151
  short_name = "RobotCode"
133
152
  version = __version__
134
153
 
135
- file_extensions: ClassVar = {
154
+ file_extensions: Set[str] = {
136
155
  "robot",
137
156
  "resource",
138
157
  "py",
@@ -141,20 +160,7 @@ class RobotLanguageServerProtocol(LanguageServerProtocol):
141
160
  "json",
142
161
  }
143
162
 
144
- language_definitions: ClassVar[List[LanguageDefinition]] = [
145
- LanguageDefinition(
146
- id="robotframework",
147
- extensions=[".robot", ".resource"],
148
- extensions_ignore_case=True,
149
- aliases=["Robot Framework", "robotframework"],
150
- ),
151
- # LanguageDefinition(
152
- # id="feature",
153
- # extensions=[".feature", ".md"],
154
- # aliases=["feature", "gherkin", "Gherkin", "cucumber"],
155
- # ),
156
- # LanguageDefinition(id="markdown", extensions=[".md"]),
157
- ]
163
+ language_definitions: List[LanguageDefinition] = [ROBOTFRAMEWORK_LANGUAGE]
158
164
 
159
165
  def __init__(
160
166
  self,
@@ -165,6 +171,12 @@ class RobotLanguageServerProtocol(LanguageServerProtocol):
165
171
  ):
166
172
  super().__init__(server)
167
173
  self.robot_profile = profile if profile is not None else RobotBaseProfile()
174
+
175
+ # the server runs in the project root, see `cli.py`
176
+ markdown = markdown_language_definition(self.robot_profile, Path.cwd())
177
+ if markdown is not None:
178
+ self.language_definitions = [*self.language_definitions, markdown]
179
+ self.file_extensions = {*self.file_extensions, *(e[1:] for e in markdown.extensions)}
168
180
  self.analysis_config = analysis_config if analysis_config is not None else WorkspaceAnalysisConfig()
169
181
  self.configuration_errors = configuration_errors if configuration_errors is not None else []
170
182
  self.robot_initialization_options = RobotInitializationOptions()
@@ -228,6 +240,10 @@ class RobotLanguageServerProtocol(LanguageServerProtocol):
228
240
  @event
229
241
  def on_robot_initialized(sender) -> None: ...
230
242
 
243
+ # where a code action places code in a language that holds Robot Framework data in other text
244
+ @event
245
+ def place_code(sender, document: TextDocument, text: str, range: Range) -> Optional[Tuple[str, Range]]: ...
246
+
231
247
  # the errors of the configuration that the start loaded, which the editors otherwise show only in the server's log
232
248
  def show_configuration_errors(self, sender: Any) -> None:
233
249
  for message in self.configuration_errors: