-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move LintManager to core, check that python is >= 3.8 in conda.yaml
- Loading branch information
Showing
34 changed files
with
2,887 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,3 +137,5 @@ robotframework-intellij/.gradle | |
|
||
# virtual environment | ||
.venv/ | ||
|
||
*.robolog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MYPY_USE_CONSOLE: false | ||
SEARCH_MYPY_LOCATION: SEARCH | ||
USE_MYPY: true | ||
MYPY_ADD_PROJECT_FOLDERS_TO_MYPYPATH: true | ||
MYPY_FILE_LOCATION: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,55 @@ | ||
ADD_COMMENTS_AT_INDENT: false | ||
ADD_NEW_LINE_AT_END_OF_FILE: true | ||
AUTOPEP8_PARAMETERS: '' | ||
BLACK_PARAMETERS: '--fast' | ||
BLACK_FORMATTER_FILE_LOCATION: '' | ||
BLACK_FORMATTER_LOCATION_OPTION: LOCATION_SEARCH | ||
BLACK_PARAMETERS: --fast | ||
BLANK_LINES_INNER: 1 | ||
BLANK_LINES_TOP_LEVEL: 2 | ||
BREAK_IMPORTS_MODE: ESCAPE | ||
DATE_FIELD_FORMAT: yyyy-MM-dd | ||
DATE_FIELD_NAME: __updated__ | ||
DELETE_UNUSED_IMPORTS: false | ||
ENABLE_DATE_FIELD_ACTION: false | ||
FORMATTER_STYLE: BLACK | ||
FORMAT_BEFORE_SAVING: true | ||
FORMAT_ONLY_CHANGED_LINES: false | ||
FROM_IMPORTS_FIRST: false | ||
GROUP_IMPORTS: true | ||
IMPORT_ENGINE: IMPORT_ENGINE_ISORT | ||
ISORT_FILE_LOCATION: '' | ||
ISORT_LOCATION_OPTION: LOCATION_SEARCH | ||
ISORT_PARAMETERS: '' | ||
MANAGE_BLANK_LINES: true | ||
MULTILINE_IMPORTS: true | ||
MULTI_BLOCK_COMMENT_CHAR: = | ||
MULTI_BLOCK_COMMENT_SHOW_ONLY_CLASS_NAME: true | ||
MULTI_BLOCK_COMMENT_SHOW_ONLY_FUNCTION_NAME: true | ||
MYPY_ADD_PROJECT_FOLDERS_TO_MYPYPATH: true | ||
MYPY_ARGS: --follow-imports=silent --show-column-numbers --namespace-packages --explicit-package-bases | ||
MYPY_FILE_LOCATION: '' | ||
MYPY_USE_CONSOLE: true | ||
PYDEV_TEST_RUNNER: '2' | ||
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv | ||
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n | ||
0 --tb=native -vv --force-regen --assert=plain | ||
PYDEV_USE_PYUNIT_VIEW: true | ||
RUFF_ARGS: '' | ||
RUFF_FILE_LOCATION: '' | ||
RUFF_USE_CONSOLE: false | ||
SAVE_ACTIONS_ONLY_ON_WORKSPACE_FILES: true | ||
SORT_IMPORTS_ON_SAVE: false | ||
SEARCH_MYPY_LOCATION: SEARCH | ||
SEARCH_RUFF_LOCATION: SEARCH | ||
SINGLE_BLOCK_COMMENT_ALIGN_RIGHT: true | ||
SINGLE_BLOCK_COMMENT_CHAR: '-' | ||
SORT_IMPORTS_ON_SAVE: true | ||
SORT_NAMES_GROUPED: false | ||
SPACES_BEFORE_COMMENT: '2' | ||
SPACES_IN_START_COMMENT: '1' | ||
TRIM_EMPTY_LINES: true | ||
TRIM_MULTILINE_LITERALS: true | ||
USE_ASSIGN_WITH_PACES_INSIDER_PARENTESIS: false | ||
USE_MYPY: true | ||
USE_OPERATORS_WITH_SPACE: true | ||
USE_RUFF: true | ||
USE_SPACE_AFTER_COMMA: true | ||
USE_SPACE_FOR_PARENTESIS: false | ||
MYPY_USE_CONSOLE: false | ||
SEARCH_MYPY_LOCATION: SEARCH | ||
USE_MYPY: true | ||
MYPY_ADD_PROJECT_FOLDERS_TO_MYPYPATH: true | ||
MYPY_FILE_LOCATION: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
import os | ||
import weakref | ||
from typing import List, Optional | ||
|
||
from robocorp_ls_core.basic import overrides | ||
from robocorp_ls_core.lsp import DiagnosticsTypedDict, LSPMessages | ||
from robocorp_ls_core.protocols import IEndPoint, IMonitor, IWorkspace | ||
from robocorp_ls_core.python_ls import BaseLintInfo, BaseLintManager | ||
from robocorp_ls_core.robotframework_log import get_logger | ||
|
||
from robocorp_code.protocols import IRcc | ||
from robocorp_code.robocorp_language_server import RobocorpLanguageServer | ||
|
||
log = get_logger(__name__) | ||
|
||
|
||
class DiagnosticsConfig: | ||
analyze_versions = True | ||
analyze_rcc = True | ||
|
||
|
||
def collect_conda_yaml_diagnostics( | ||
workspace: IWorkspace, conda_yaml_uri: str, monitor: Optional[IMonitor] | ||
) -> List[DiagnosticsTypedDict]: | ||
from robocorp_code.deps import analyzer | ||
|
||
if not DiagnosticsConfig.analyze_versions: | ||
return [] | ||
|
||
doc = workspace.get_document(conda_yaml_uri, accept_from_file=True) | ||
if doc is None: | ||
return [] | ||
if monitor: | ||
monitor.check_cancelled() | ||
return list(analyzer.Analyzer(doc.source, doc.path).iter_issues()) | ||
|
||
|
||
def collect_rcc_configuration_diagnostics( | ||
rcc: IRcc, robot_yaml_fs_path | ||
) -> List[DiagnosticsTypedDict]: | ||
import json | ||
|
||
from robocorp_ls_core.lsp import DiagnosticSeverity | ||
|
||
ret: List[DiagnosticsTypedDict] = [] | ||
|
||
if not DiagnosticsConfig.analyze_rcc: | ||
return ret | ||
|
||
action_result = rcc.configuration_diagnostics(robot_yaml_fs_path) | ||
if action_result.success: | ||
json_contents = action_result.result | ||
if not json_contents: | ||
return ret | ||
|
||
as_dict = json.loads(json_contents) | ||
checks = as_dict.get("checks", []) | ||
ret = [] | ||
|
||
CategoryLockFile = 1020 | ||
CategoryLockPid = 1021 | ||
|
||
if isinstance(checks, (list, tuple)): | ||
for check in checks: | ||
if isinstance(check, dict): | ||
status = check.get("status", "ok").lower() | ||
|
||
if status != "ok": | ||
if check.get("category") in ( | ||
CategoryLockFile, | ||
CategoryLockPid, | ||
): | ||
continue | ||
|
||
# Default is error (for fail/fatal) | ||
severity = DiagnosticSeverity.Error | ||
|
||
if status in ("warn", "warning"): | ||
severity = DiagnosticSeverity.Warning | ||
elif status in ("info", "information"): | ||
severity = DiagnosticSeverity.Information | ||
|
||
# The actual line is not given by rcc, so, put | ||
# all errors in the first 2 lines. | ||
message = check.get("message", "<unable to get error message>") | ||
|
||
url = check.get("url") | ||
if url: | ||
message += f" -- see: {url} for more information." | ||
dct: DiagnosticsTypedDict = { | ||
"range": { | ||
"start": {"line": 0, "character": 0}, | ||
"end": {"line": 1, "character": 0}, | ||
}, | ||
"severity": severity, | ||
"source": "robocorp-code", | ||
"message": message, | ||
} | ||
ret.append(dct) | ||
return ret | ||
|
||
|
||
class _CurrLintInfo(BaseLintInfo): | ||
def __init__( | ||
self, | ||
weak_robocorp_language_server: "weakref.ref[RobocorpLanguageServer]", | ||
rcc: IRcc, | ||
lsp_messages: LSPMessages, | ||
doc_uri, | ||
is_saved, | ||
weak_lint_manager, | ||
) -> None: | ||
self._rcc: IRcc = rcc | ||
self._weak_robocorp_language_server = weak_robocorp_language_server | ||
BaseLintInfo.__init__(self, lsp_messages, doc_uri, is_saved, weak_lint_manager) | ||
|
||
@overrides(BaseLintInfo._do_lint) | ||
def _do_lint(self) -> None: | ||
from concurrent import futures | ||
|
||
from robocorp_ls_core import uris | ||
|
||
is_saved = self.is_saved | ||
doc_uri = self.doc_uri | ||
|
||
if doc_uri.endswith("conda.yaml") or doc_uri.endswith("robot.yaml"): | ||
robot_yaml_fs_path = uris.to_fs_path(doc_uri) | ||
if robot_yaml_fs_path.endswith("conda.yaml"): | ||
p = os.path.dirname(robot_yaml_fs_path) | ||
for _ in range(3): | ||
target = os.path.join(p, "robot.yaml") | ||
if target and os.path.exists(target): | ||
robot_yaml_fs_path = target | ||
break | ||
else: | ||
# We didn't find the 'robot.yaml' for the 'conda.yaml' | ||
# bail out. | ||
return | ||
|
||
# Get the executor service from the endpoint | ||
endpoint = self._lsp_messages.endpoint | ||
|
||
# When a document is saved, if it's a conda.yaml or a robot.yaml, | ||
# validate it with RCC. | ||
if is_saved: | ||
executor_service: futures.ThreadPoolExecutor = getattr( | ||
endpoint, "executor_service" | ||
) | ||
|
||
future_diagnostics = executor_service.submit( | ||
collect_rcc_configuration_diagnostics, | ||
self._rcc, | ||
robot_yaml_fs_path, | ||
) | ||
|
||
found = [] | ||
# Ok, we started collecting RCC diagnostics in a thread. We | ||
# can now also collect other diagnostics here. | ||
if doc_uri.endswith("conda.yaml"): | ||
robocorp_language_server = self._weak_robocorp_language_server() | ||
if robocorp_language_server is not None: | ||
ws = robocorp_language_server.workspace | ||
if ws is not None: | ||
found.extend( | ||
collect_conda_yaml_diagnostics(ws, doc_uri, self._monitor) | ||
) | ||
|
||
if is_saved: | ||
found.extend(future_diagnostics.result()) | ||
|
||
self._lsp_messages.publish_diagnostics(doc_uri, found) | ||
|
||
|
||
class LintManager(BaseLintManager): | ||
def __init__( | ||
self, | ||
robocorp_language_server: RobocorpLanguageServer, | ||
rcc: IRcc, | ||
lsp_messages, | ||
endpoint: IEndPoint, | ||
read_queue, | ||
) -> None: | ||
|
||
self._rcc: IRcc = rcc | ||
self._weak_robocorp_language_server = weakref.ref(robocorp_language_server) | ||
BaseLintManager.__init__(self, lsp_messages, endpoint, read_queue) | ||
|
||
@overrides(BaseLintManager._create_curr_lint_info) | ||
def _create_curr_lint_info( | ||
self, doc_uri: str, is_saved: bool, timeout: float | ||
) -> Optional[BaseLintInfo]: | ||
# Note: this call must be done in the main thread. | ||
weak_lint_manager = weakref.ref(self) | ||
|
||
log.debug("Schedule lint for: %s", doc_uri) | ||
curr_info = _CurrLintInfo( | ||
self._weak_robocorp_language_server, | ||
self._rcc, | ||
self._lsp_messages, | ||
doc_uri, | ||
is_saved, | ||
weak_lint_manager, | ||
) | ||
return curr_info |
Empty file.
Oops, something went wrong.