Skip to content

Commit

Permalink
Robocop linter now opt in. Fixes #312
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Apr 14, 2021
1 parent b6b0b71 commit c40c822
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 13 deletions.
6 changes: 5 additions & 1 deletion robocorp-python-ls-core/src/robocorp_ls_core/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from robocorp_ls_core.lsp import TextDocumentContentChangeEvent
from robocorp_ls_core.lsp import HoverResponseTypedDict
from robocorp_ls_core.lsp import TextDocumentTypedDict
from robocorp_ls_core.lsp import ResponseTypedDict

# Hack so that we don't break the runtime on versions prior to Python 3.8.
if sys.version_info[:2] < (3, 8):
Expand Down Expand Up @@ -223,7 +224,7 @@ def initialize(
def get_version(self):
pass

def lint(self, doc_uri: str) -> list:
def lint(self, doc_uri: str) -> "ResponseTypedDict":
pass

def request_lint(self, doc_uri: str) -> Optional[IIdMessageMatcher]:
Expand Down Expand Up @@ -305,6 +306,9 @@ def request_workspace_symbols(
:Note: async complete.
"""

def settings(self, settings: Dict):
pass


class ILanguageServerClient(ILanguageServerClientBase, Protocol):
pid: Optional[int]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class FeatureSemanticHighlighting extends ExternalAnnotator<EditorLanguag
@Override
public @Nullable Pair<SemanticTokens, EditorLanguageServerConnection> doAnnotate(EditorLanguageServerConnection connection) {
try {
if (connection == null) {
return null;
}
CompletableFuture<SemanticTokens> semanticTokens = connection.getSemanticTokens();
if (semanticTokens == null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion robotframework-ls/.settings/org.python.pydev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MULTI_BLOCK_COMMENT_CHAR: '='
MULTI_BLOCK_COMMENT_SHOW_ONLY_CLASS_NAME: true
MULTI_BLOCK_COMMENT_SHOW_ONLY_FUNCTION_NAME: true
PYDEV_TEST_RUNNER: '2'
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv --force-regen
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n auto --tb=native -vv --force-regen
PYDEV_USE_PYUNIT_VIEW: true
SAVE_ACTIONS_ONLY_ON_WORKSPACE_FILES: true
SINGLE_BLOCK_COMMENT_ALIGN_RIGHT: true
Expand Down
6 changes: 3 additions & 3 deletions robotframework-ls/docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ Example of `.robocop` file:
--exclude missing-doc-suite
```

How to disable the Robocop linter?
How to enable the Robocop linter?
---------------------------------------

To completely disable the `Robocop` linter, change the setting:
To enable the `Robocop` linter, change the setting:

`robot.lint.robocop.enabled`

to `false` (in the Intellij UI, it's the `Lint Robocop Enabled` setting).
to `true` (in the Intellij UI, it's the `Lint Robocop Enabled` setting).


How to change the Robocop version used?
Expand Down
2 changes: 1 addition & 1 deletion robotframework-ls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
},
"robot.lint.robocop.enabled": {
"type": "boolean",
"default": true,
"default": false,
"description": "Specifies whether to lint with Robocop."
},
"robot.completions.section_headers.form": {
Expand Down
21 changes: 17 additions & 4 deletions robotframework-ls/src/robotframework_ls/server_api/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Optional
from typing import Optional, Dict

from robocorp_ls_core.client_base import LanguageServerClientBase
from robocorp_ls_core.protocols import IIdMessageMatcher
from robocorp_ls_core.lsp import TextDocumentTypedDict
from robocorp_ls_core.protocols import IIdMessageMatcher, IRobotFrameworkApiClient
from robocorp_ls_core.lsp import TextDocumentTypedDict, ResponseTypedDict
from robocorp_ls_core.basic import implements


class SubprocessDiedError(Exception):
Expand Down Expand Up @@ -48,6 +49,17 @@ def initialize(
timeout=30 if USE_TIMEOUTS else NO_TIMEOUT,
)

@implements(IRobotFrameworkApiClient.settings)
def settings(self, settings: Dict):
self.request(
{
"jsonrpc": "2.0",
"id": self.next_id(),
"method": "workspace/didChangeConfiguration",
"params": settings,
}
)

def get_version(self):
"""
:return:
Expand All @@ -67,7 +79,8 @@ def get_version(self):

return self._version

def lint(self, doc_uri) -> list:
@implements(IRobotFrameworkApiClient.lint)
def lint(self, doc_uri) -> ResponseTypedDict:
self._check_process_alive()
msg_id = self.next_id()
return self.request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _threaded_lint(self, doc_uri, monitor: IMonitor):

config = completion_context.config
robocop_enabled = config is None or config.get_setting(
OPTION_ROBOT_LINT_ROBOCOP_ENABLED, bool, True
OPTION_ROBOT_LINT_ROBOCOP_ENABLED, bool, False
)

ast = completion_context.get_ast()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def test_server(server_api_process_io: IRobotFrameworkApiClient, data_regression
from robotframework_ls_tests.fixtures import sort_diagnostics

server_api_process_io.initialize(process_id=os.getpid())
server_api_process_io.settings({"settings": {"robot.lint.robocop.enabled": True}})

assert server_api_process_io.get_version() >= "3.2"

server_api_process_io.open("untitled", 1, "*** foo bar ***")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def test_diagnostics(language_server, ws_root_path, data_regression):
env = {
"PYTHONPATH": os.path.dirname(os.path.dirname(os.path.abspath(robot.__file__)))
}
language_server.settings({"settings": {"robot": {"python": {"env": env}}}})
language_server.settings(
{"settings": {"robot.python.env": env, "robot.lint.robocop.enabled": True}}
)
check_diagnostics(language_server, data_regression)


Expand All @@ -43,6 +45,8 @@ def test_diagnostics_robocop(language_server, ws_root_path, data_regression):

language_server.initialize(ws_root_path, process_id=os.getpid())

language_server.settings({"settings": {"robot.lint.robocop.enabled": True}})

uri = "untitled:Untitled-1"
message_matcher = language_server.obtain_pattern_message_matcher(
{"method": "textDocument/publishDiagnostics"}
Expand Down Expand Up @@ -78,6 +82,7 @@ def test_diagnostics_robocop_configuration_file(
from robocorp_ls_core import uris

language_server.initialize(ws_root_path, process_id=os.getpid())
language_server.settings({"settings": {"robot.lint.robocop.enabled": True}})
src = os.path.join(ws_root_path, "my", "src")
os.makedirs(src)
target_robot = os.path.join(src, "target.robot")
Expand Down Expand Up @@ -458,7 +463,9 @@ def on_get_robotframework_api_client(server_api):
os.path.dirname(os.path.abspath(robot.__file__))
)
}
language_server_tcp.settings({"settings": {"robot": {"python": {"env": env}}}})
language_server_tcp.settings(
{"settings": {"robot.python.env": env, "robot.lint.robocop.enabled": True}}
)

processes_per_api = 3

Expand Down

0 comments on commit c40c822

Please sign in to comment.