Skip to content

Commit

Permalink
Merge pull request #1 from sparshg/update
Browse files Browse the repository at this point in the history
Update extension to work with latest tach version
  • Loading branch information
caelean authored Aug 23, 2024
2 parents 29e7877 + 326b433 commit 5f23bec
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 241 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@


### Setup
1. Install the extension
2. Navigate to the settings for the extension in VS Code. `Extensions > Tach`
3. Add two arguments to `Tach:Args`:
1. `--root`
2. `path/to/tach.yml/dir`
4. Run `Tach: Restart Server` from the command palette (`CMD+SHFT+P`)
5. That's it! You should see invalid imports highlighted as errors on save.
1. Install the extension and you should see invalid imports highlighted as errors on save.
2. Navigate to the settings for the extension in `Extensions > Tach` to set arguments if needed.
3. Run `Tach: Restart Server` from the command palette (`CMD+SHFT+P`) to restart the server.

If you run into any issues, let us know by either reaching out on [Discord](https://discord.gg/a58vW8dnmw) or submitting a [Github Issue](https://github.com/gauge-sh/tach/issues)!
22 changes: 9 additions & 13 deletions bundled/tool/lsp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
import traceback
from typing import Any
from tach.check import CheckResult


# **********************************************************
Expand Down Expand Up @@ -99,30 +100,25 @@ def did_close(params: lsp.DidCloseTextDocumentParams) -> None:


def _linting_helper(document: workspace.Document) -> list[lsp.Diagnostic]:
boundary_errors = _run_tool_on_document(document)
return (
_parse_boundary_errors(boundary_errors, document.uri) if boundary_errors else []
)
checked_result = _run_tool_on_document(document)
return _parse_boundary_errors(checked_result, document.uri)


def _parse_boundary_errors(boundary_errors, uri):
def _parse_boundary_errors(checked_result: CheckResult, uri):
diagnostics = []
for boundary_error in boundary_errors:
if (
boundary_error.file_path in uri
and boundary_error.error_info.exception_message
):
for err in checked_result.errors:
if str(err.file_path) in uri and err.error_info.exception_message:
start = lsp.Position(
line=boundary_error.line_number - 1,
line=err.line_number - 1,
character=0,
)
end = lsp.Position(line=boundary_error.line_number - 1, character=99999)
end = lsp.Position(line=err.line_number - 1, character=99999)
diagnostic = lsp.Diagnostic(
range=lsp.Range(
start=start,
end=end,
),
message=boundary_error.error_info.exception_message,
message=err.error_info.exception_message,
severity=lsp.DiagnosticSeverity.Error,
source=TOOL_MODULE,
)
Expand Down
16 changes: 6 additions & 10 deletions bundled/tool/tach_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from tach.check import BoundaryError, check
from tach.check import CheckResult, check
from tach.cli import parse_arguments
from tach.colors import BCOLORS
from tach.constants import CONFIG_FILE_NAME
Expand All @@ -11,9 +11,7 @@

def run_tach_check(argv: list[str], path: str):
args, _ = parse_arguments(argv[1:])
root = args.root
if args.root == ".":
root = find_project_config_root(path)
root = find_project_config_root()
if not root:
raise TachSetupError("Project config root not found")
exclude_paths = args.exclude.split(",") if getattr(args, "exclude", None) else None
Expand All @@ -28,12 +26,10 @@ def run_tach_check(argv: list[str], path: str):
else:
exclude_paths = project_config.exclude

boundary_errors: list[BoundaryError] = check(
root,
project_config,
exclude_paths=exclude_paths,
checked_result: CheckResult = check(
project_root=root, project_config=project_config, exclude_paths=exclude_paths
)
for boundary_error in boundary_errors:
for boundary_error in checked_result.errors:
# Hack for now - update error message displayed to user
error_info = boundary_error.error_info
if (
Expand All @@ -44,4 +40,4 @@ def run_tach_check(argv: list[str], path: str):
f"Cannot import '{boundary_error.import_mod_path}'. "
f"Module '{error_info.source_module}' cannot depend on '{error_info.invalid_module}'."
)
return boundary_errors
return checked_result
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tach",
"displayName": "Tach",
"description": "Linting support for python files using `tach`.",
"version": "0.5.21",
"version": "0.10.0",
"preview": true,
"serverInfo": {
"name": "Tach",
Expand Down
Loading

0 comments on commit 5f23bec

Please sign in to comment.