From ba56c45b759ed6d30790bdb79f161d7f7548b840 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 18:53:42 -0700 Subject: [PATCH 1/4] errors with no type should not display as `error: [None]` Signed-off-by: Jade Abraham --- tools/chapel-py/src/chapel/lsp/__init__.py | 11 ++++++++--- tools/chapel-py/src/method-tables/core-methods.h | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/chapel-py/src/chapel/lsp/__init__.py b/tools/chapel-py/src/chapel/lsp/__init__.py index 2f4f9f1453ff..64fb88f20b71 100644 --- a/tools/chapel-py/src/chapel/lsp/__init__.py +++ b/tools/chapel-py/src/chapel/lsp/__init__.py @@ -45,11 +45,16 @@ def error_to_diagnostic(error) -> Diagnostic: "warning": DiagnosticSeverity.Warning, } + type_ = error.type() + if type_ is not None: + message = "{}: [{}]: {}".format( + error.kind().capitalize(), type_, error.message() + ) + else: + message = "{}: {}".format(error.kind().capitalize(), error.message()) diagnostic = Diagnostic( range=location_to_range(error.location()), - message="{}: [{}]: {}".format( - error.kind().capitalize(), error.type(), error.message() - ), + message=message, severity=kind_to_severity[error.kind()], ) return diagnostic diff --git a/tools/chapel-py/src/method-tables/core-methods.h b/tools/chapel-py/src/method-tables/core-methods.h index 24e27b8cd2f7..f61edc8db86b 100644 --- a/tools/chapel-py/src/method-tables/core-methods.h +++ b/tools/chapel-py/src/method-tables/core-methods.h @@ -143,7 +143,10 @@ CLASS_BEGIN(Error) PLAIN_GETTER(Error, kind, "Retrieve the kind ('error', 'warning') of this type of error", const char*, return chpl::ErrorBase::getKindName(node->kind())) PLAIN_GETTER(Error, type, "Retrieve the unique name of this type of error", - const char*, return chpl::ErrorBase::getTypeName(node->type())) + std::optional, + const char* name = chpl::ErrorBase::getTypeName(node->type()); + return name ? std::optional(name) : std::nullopt; + ) CLASS_END(Error) CLASS_BEGIN(ErrorManager) From 55cb2353d2dbb819e2a1515ffab791e7e527b87c Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 18:54:17 -0700 Subject: [PATCH 2/4] fix resolution errors being hidden Signed-off-by: Jade Abraham --- tools/chpl-language-server/src/chpl-language-server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/chpl-language-server/src/chpl-language-server.py b/tools/chpl-language-server/src/chpl-language-server.py index 32d310c74eab..713ef6982d03 100755 --- a/tools/chpl-language-server/src/chpl-language-server.py +++ b/tools/chpl-language-server/src/chpl-language-server.py @@ -688,8 +688,7 @@ def rebuild_index(self): self._collect_possibly_visible_decls(asts) if self.use_resolver: - with self.context.context.track_errors() as _: - self._search_instantiations(asts) + self._search_instantiations(asts) def called_function_at_position( self, position: Position From 5e4662227b491374934e7854fd3d1945d9e91072 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 3 Jun 2024 18:54:40 -0700 Subject: [PATCH 3/4] fix dead code not rendering right for multi-branch conditionals Signed-off-by: Jade Abraham --- tools/chpl-language-server/src/chpl-language-server.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/chpl-language-server/src/chpl-language-server.py b/tools/chpl-language-server/src/chpl-language-server.py index 713ef6982d03..1f6172464263 100755 --- a/tools/chpl-language-server/src/chpl-language-server.py +++ b/tools/chpl-language-server/src/chpl-language-server.py @@ -258,6 +258,8 @@ def encode_deltas( to it: each line is encoded as a delta from the previous line, and each column is encoded as a delta from the previous column. + `tokens` must be sorted by line number, and then by column number within + Returns tokens with type token_type, and modifiers token_modifiers. """ @@ -1852,6 +1854,8 @@ async def semantic_tokens_range( ls.get_dead_code_tokens(ast, fi.file_lines(), instantiation) ) + # sort tokens by line number, and then by column number + tokens.sort(key=lambda x: (x[0], x[1])) return SemanticTokens(data=encode_deltas(tokens, 0, 0)) @server.feature(TEXT_DOCUMENT_PREPARE_CALL_HIERARCHY) From 2cef07a4b9c020279062e4e74fb2cc3bf310702f Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Tue, 4 Jun 2024 10:13:25 -0700 Subject: [PATCH 4/4] re-suppress resolution errors with a comment Signed-off-by: Jade Abraham --- tools/chpl-language-server/src/chpl-language-server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/chpl-language-server/src/chpl-language-server.py b/tools/chpl-language-server/src/chpl-language-server.py index 1f6172464263..aba5c43f14d3 100755 --- a/tools/chpl-language-server/src/chpl-language-server.py +++ b/tools/chpl-language-server/src/chpl-language-server.py @@ -690,7 +690,10 @@ def rebuild_index(self): self._collect_possibly_visible_decls(asts) if self.use_resolver: - self._search_instantiations(asts) + # TODO: suppress resolution errors due to false-positives + # this should be removed once the resolver is finished + with self.context.context.track_errors() as _: + self._search_instantiations(asts) def called_function_at_position( self, position: Position