Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,26 @@ def format_robocop(

config_manager = self.parent.robocop_helper.get_config_manager(workspace_folder)

source = document.uri.to_path()
config = config_manager.get_config_for_source_file(document.uri.to_path())

if range is not None:
config.formatter.start_line = range.start.line + 1
config.formatter.end_line = range.end.line + 1

# TODO: not cached, we load all formatters everytime - but it's small cost
runner = RobocopFormatter(config_manager)
runner.config = config

model = self.parent.documents_cache.get_model(document, False)
_, _, new, _ = runner.format_until_stable(model)
if get_robot_version() >= (8, 0):
from robocop.source_file import SourceFile

# overwrite _model to stop Robocop from loading it
source_file = SourceFile(path=source, config=config, _model=model)
_, _, new, _ = runner.format_until_stable(source_file)
else:
_, _, new, _ = runner.format_until_stable(model)

if new.text == document.text():
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def get_config(self, document: TextDocument) -> Optional[RoboCopConfig]:

return self.parent.workspace.get_configuration(RoboCopConfig, folder.uri)

def get_linter(self, workspace_folder: WorkspaceFolder) -> "RobocopLinter":
linter = self._robocop_linters.get(workspace_folder, None)

if linter is None:
config_manager = self.parent.robocop_helper.get_config_manager(workspace_folder)
linter = RobocopLinter(config_manager)
self._robocop_linters[workspace_folder] = linter
return linter

@language_id("robotframework")
@_logger.call
def collect_diagnostics(
Expand All @@ -69,23 +78,21 @@ def collect_diagnostics(
@_logger.call
def collect(self, document: TextDocument, workspace_folder: WorkspaceFolder) -> List[Diagnostic]:
from robocop.linter.rules import RuleSeverity
from robocop.linter.runner import RobocopLinter

linter = self._robocop_linters.get(workspace_folder, None)

if linter is None:
config_manager = self.parent.robocop_helper.get_config_manager(workspace_folder)

config = config_manager.get_config_for_source_file(document.uri.to_path())

linter = RobocopLinter(config_manager)
self._robocop_linters[workspace_folder] = linter
linter = self.get_linter(workspace_folder)

source = document.uri.to_path()

config = linter.config_manager.get_config_for_source_file(source)
model = self.parent.documents_cache.get_model(document, False)
diagnostics = linter.run_check(model, source, config)

if self.parent.robocop_helper.robocop_version >= (8, 0):
from robocop.source_file import SourceFile

# overwrite _model to stop Robocop from loading it
source_file = SourceFile(path=source, config=config, _model=model)
diagnostics = linter.run_check(source_file)
else:
diagnostics = linter.run_check(model, source, config)

return [
Diagnostic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..protocol import RobotLanguageServerProtocol

if TYPE_CHECKING:
from robocop.config import ConfigManager
from robocop.config.manager import ConfigManager


class RobocopConfigError(Exception):
Expand Down Expand Up @@ -59,7 +59,10 @@ def get_robocop_config(self, resource: Union[TextDocument, WorkspaceFolder]) ->
return self.parent.workspace.get_configuration(RoboCopConfig, folder.uri)

def get_config_manager(self, workspace_folder: WorkspaceFolder) -> "ConfigManager":
from robocop.config import ConfigManager
if self.parent.robocop_helper.robocop_version >= (8, 0):
from robocop.config.manager import ConfigManager
else:
from robocop.config import ConfigManager

if workspace_folder in self._config_managers:
return self._config_managers[workspace_folder]
Expand Down