Skip to content

Commit

Permalink
Merge pull request #19 from Retsediv/feature/ignore-lines
Browse files Browse the repository at this point in the history
Ignore line diagnostics
  • Loading branch information
Retsediv authored Jan 28, 2024
2 parents 1673893 + fabd963 commit d900930
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 151 deletions.
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

0 comments on commit d900930

Please sign in to comment.