-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32741 from vespa-engine/interns/magnus/resolve-sy…
…mbols Interns/magnus/resolve symbols
- Loading branch information
Showing
10 changed files
with
188 additions
and
37 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...uage-server/language-server/src/main/java/ai/vespa/schemals/SchemaDiagnosticsHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,63 @@ | ||
package ai.vespa.schemals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.PublishDiagnosticsParams; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
|
||
import ai.vespa.schemals.common.SchemaDiagnostic.DiagnosticCode; | ||
|
||
/** | ||
* SchemaDiagnosticHandler is a wrapper for publishing diagnostics to the client | ||
*/ | ||
public class SchemaDiagnosticsHandler { | ||
private LanguageClient client; | ||
// Represents the previous list of diagnostics sent to the client for a given document | ||
private Map<String, List<Diagnostic>> documentDiagnostics = new HashMap<>(); | ||
|
||
public void connectClient(LanguageClient client) { | ||
this.client = client; | ||
} | ||
|
||
public void clearDiagnostics(String fileURI) { | ||
publishDiagnostics(fileURI, new ArrayList<Diagnostic>()); | ||
documentDiagnostics.remove(fileURI); | ||
} | ||
|
||
public void publishDiagnostics(String fileURI, List<Diagnostic> diagnostics) { | ||
insertDocumentIfNotExists(fileURI); | ||
|
||
client.publishDiagnostics( | ||
new PublishDiagnosticsParams( | ||
fileURI, | ||
diagnostics | ||
) | ||
); | ||
|
||
documentDiagnostics.get(fileURI).clear(); | ||
documentDiagnostics.get(fileURI).addAll(diagnostics); | ||
} | ||
|
||
public void replaceUndefinedSymbolDiagnostics(String fileURI, List<Diagnostic> unresolvedSymbolDiagnostics) { | ||
Predicate<Diagnostic> undefinedSymbolPredicate = | ||
(diagnostic) -> ( | ||
diagnostic.getCode().isRight() | ||
&& diagnostic.getCode().getRight().equals(DiagnosticCode.UNDEFINED_SYMBOL.ordinal())); | ||
|
||
insertDocumentIfNotExists(fileURI); | ||
documentDiagnostics.get(fileURI).removeIf(undefinedSymbolPredicate); | ||
documentDiagnostics.get(fileURI).addAll(unresolvedSymbolDiagnostics.stream().filter(undefinedSymbolPredicate).toList()); | ||
|
||
publishDiagnostics(fileURI, List.copyOf(documentDiagnostics.get(fileURI))); | ||
} | ||
|
||
private void insertDocumentIfNotExists(String fileURI) { | ||
if (documentDiagnostics.containsKey(fileURI)) return; | ||
documentDiagnostics.put(fileURI, new ArrayList<>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.