diff --git a/src/solidlsp/ls.py b/src/solidlsp/ls.py index a0be83cc..2604b8ac 100644 --- a/src/solidlsp/ls.py +++ b/src/solidlsp/ls.py @@ -91,7 +91,7 @@ class DocumentSymbols: self.root_symbols = root_symbols self._all_symbols: list[ls_types.UnifiedSymbolInformation] | None = None - def __getstate__(self): + def __getstate__(self) -> dict: return getstate(DocumentSymbols, self, transient_properties=["_all_symbols"]) def iter_symbols(self) -> Iterator[ls_types.UnifiedSymbolInformation]: @@ -103,7 +103,7 @@ class DocumentSymbols: yield from self._all_symbols return - def traverse(s: ls_types.UnifiedSymbolInformation): + def traverse(s: ls_types.UnifiedSymbolInformation) -> Iterator[ls_types.UnifiedSymbolInformation]: yield s for child in s.get("children", []): yield from traverse(child) @@ -297,7 +297,7 @@ class SolidLanguageServer(ABC): self.completions_available = threading.Event() if config.trace_lsp_communication: - def logging_fn(source: str, target: str, msg: StringDict | str): + def logging_fn(source: str, target: str, msg: StringDict | str) -> None: self.logger.log(f"LSP: {source} -> {target}: {msg!s}", self.logger.logger.level) else: @@ -673,10 +673,10 @@ class SolidLanguageServer(ABC): new_item.update(item) new_item["absolutePath"] = PathUtils.uri_to_path(new_item["uri"]) new_item["relativePath"] = PathUtils.get_relative_path(new_item["absolutePath"], self.repository_root_path) - ret.append(ls_types.Location(new_item)) + ret.append(ls_types.Location(**new_item)) # type: ignore elif LSPConstants.TARGET_URI in item and LSPConstants.TARGET_RANGE in item and LSPConstants.TARGET_SELECTION_RANGE in item: - new_item: ls_types.Location = {} - new_item["uri"] = item[LSPConstants.TARGET_URI] + new_item: dict = {} # type: ignore + new_item["uri"] = item[LSPConstants.TARGET_URI] # type: ignore new_item["absolutePath"] = PathUtils.uri_to_path(new_item["uri"]) new_item["relativePath"] = PathUtils.get_relative_path(new_item["absolutePath"], self.repository_root_path) new_item["range"] = item[LSPConstants.TARGET_SELECTION_RANGE] # type: ignore @@ -688,7 +688,7 @@ class SolidLanguageServer(ABC): assert LSPConstants.URI in response assert LSPConstants.RANGE in response - new_item = {} + new_item: dict = {} # type: ignore new_item.update(response) new_item["absolutePath"] = PathUtils.uri_to_path(new_item["uri"]) new_item["relativePath"] = PathUtils.get_relative_path(new_item["absolutePath"], self.repository_root_path) @@ -802,18 +802,18 @@ class SolidLanguageServer(ABC): with self.open_file(relative_file_path): response = self.server.send.text_document_diagnostic( { - LSPConstants.TEXT_DOCUMENT: { + LSPConstants.TEXT_DOCUMENT: { # type: ignore LSPConstants.URI: pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri() } } ) if response is None: - return [] + return [] # type: ignore assert isinstance(response, dict), f"Unexpected response from Language Server (expected list, got {type(response)}): {response}" ret: list[ls_types.Diagnostic] = [] - for item in response["items"]: + for item in response["items"]: # type: ignore new_item: ls_types.Diagnostic = { "uri": pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri(), "severity": item["severity"], diff --git a/src/solidlsp/ls_handler.py b/src/solidlsp/ls_handler.py index 5013c2fc..e8ddbcae 100644 --- a/src/solidlsp/ls_handler.py +++ b/src/solidlsp/ls_handler.py @@ -315,7 +315,7 @@ class SolidLanguageServerHandler: if self.logger is not None: self.logger("client", "logger", message) - def _read_bytes_from_process(self, process, stream, num_bytes): + def _read_bytes_from_process(self, process, stream, num_bytes) -> bytes: # type: ignore """Read exactly num_bytes from process stdout""" data = b"" while len(data) < num_bytes: @@ -385,9 +385,9 @@ class SolidLanguageServerHandler: line = self.process.stderr.readline() if not line: continue - line = line.decode(ENCODING, errors="replace") - level = self._determine_log_level(line) - log.log(level, line) + line_str = line.decode(ENCODING, errors="replace") + level = self._determine_log_level(line_str) + log.log(level, line_str) except Exception as e: log.error("Error while reading stderr from language server process: %s", e, exc_info=e) if not self._is_shutting_down: diff --git a/src/solidlsp/ls_types.py b/src/solidlsp/ls_types.py index bbd3cbad..bc4b05f3 100644 --- a/src/solidlsp/ls_types.py +++ b/src/solidlsp/ls_types.py @@ -409,4 +409,4 @@ def extract_text_edits(workspace_edit: WorkspaceEdit) -> dict[str, list[TextEdit changes[uri] = edits return changes else: - raise f"Invalid WorkspaceEdit (expected 'changes' or 'documentChanges' key):\n{workspace_edit}" + raise Exception(f"Invalid WorkspaceEdit (expected 'changes' or 'documentChanges' key):\n{workspace_edit}") diff --git a/src/solidlsp/util/subprocess_util.py b/src/solidlsp/util/subprocess_util.py index 718d7afa..c0735f0c 100644 --- a/src/solidlsp/util/subprocess_util.py +++ b/src/solidlsp/util/subprocess_util.py @@ -2,7 +2,7 @@ import platform import subprocess -def subprocess_kwargs(): +def subprocess_kwargs() -> dict: """ Returns a dictionary of keyword arguments for subprocess calls, adding platform-specific flags that we want to use consistently. diff --git a/src/solidlsp/util/zip.py b/src/solidlsp/util/zip.py index d93d9421..bf014923 100644 --- a/src/solidlsp/util/zip.py +++ b/src/solidlsp/util/zip.py @@ -115,7 +115,7 @@ class SafeZipExtractor: """ if sys.platform.startswith("win"): return Path(rf"\\?\{os.path.abspath(path)}") - return path + return path # type: ignore # Example usage: