Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore line diagnostics #19

Merged
merged 5 commits into from
Jan 28, 2024
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

2. Using poetry: `poetry install`

## Features

1. Ignore certain lines - if you do not want to perform diagnostics on specific line, then add `# hydra: skip` to the end of that line

## How to use

To try it out, use the following code snippet in neovim.
Expand Down
20 changes: 17 additions & 3 deletions hydra_lsp/intel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
)

logger = logging.getLogger(__name__)

LocParams = (
lsp_types.TextDocumentPositionParams
| lsp_types.HoverParams
| lsp_types.ReferenceParams
)

P = ParamSpec("P")
R = TypeVar("R")


def intel(feature: str, context_required: bool = True):
def wrapper(
f: Callable[Concatenate[Any, LocParams, Optional[HydraContext], P], R]
f: Callable[Concatenate[Any, LocParams, Optional[HydraContext], P], R],
) -> Callable[..., R | None]:
@wraps(f)
def _impl(
_self,
params: LocParams,
context: Optional[HydraContext],
*args: P.args,
**kwargs: P.kwargs
**kwargs: P.kwargs,
) -> R | None:
logger.info(f"{feature} requested: {params}")

Expand Down Expand Up @@ -149,6 +149,19 @@ def get_diagnostics(self, context: HydraContext | None, doc_uri: str | None):
if doc_uri is not None and loc.uri != doc_uri:
continue

# check if there is "# hydra: skip" in the line
# if so, skip the diagnostic for that block
lines = self.ls.workspace.get_document(loc.uri).lines
skip = any(
filter(
lambda s: "# hydra: skip" in s,
lines[loc.range.start.line : loc.range.end.line + 1],
)
)

if skip:
continue

diagnostics.append(
lsp_types.Diagnostic(
range=loc.range,
Expand All @@ -158,4 +171,5 @@ def get_diagnostics(self, context: HydraContext | None, doc_uri: str | None):
)

logger.debug(f"Diagnostics: {diagnostics}")

return diagnostics
Loading
Loading