Skip to content

Commit

Permalink
fixed highlighting semantic token error when no schema is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
diyaayay committed Mar 18, 2024
1 parent 544eeab commit 3ff7856
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions language-server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ const getTokenBuilder = (uri) => {
const buildTokens = (builder, document, settings) => {
const instance = JsoncInstance.fromTextDocument(document);
const $schema = instance.get("#/$schema");
const dialectUri = $schema?.value() ?? settings.defaultDialect;
let dialectUri;
try {
dialectUri = $schema?.value() ?? settings.defaultDialect;
} catch (error) {
// SKIP
}

const schemaResources = decomposeSchemaDocument(instance, dialectUri);
for (const { keywordInstance, tokenType, tokenModifier } of getSemanticTokens(schemaResources)) {
const startPosition = keywordInstance.startPosition();
Expand Down Expand Up @@ -335,17 +341,18 @@ connection.languages.semanticTokens.on(async ({ textDocument }) => {
}
});

connection.languages.semanticTokens.onDelta(({ textDocument, previousResultId }) => {
connection.languages.semanticTokens.onDelta(async ({ textDocument, previousResultId }) => {
connection.console.log(`semanticTokens.onDelta: ${textDocument.uri}`);

const document = documents.get(textDocument.uri);
const settings = await getDocumentSettings(document.uri);
if (document === undefined) {
return { edits: [] };
}

const builder = getTokenBuilder(document);
builder.previousResult(previousResultId);
buildTokens(builder, document);
buildTokens(builder, document, settings);

return builder.buildEdits();
});
Expand Down

0 comments on commit 3ff7856

Please sign in to comment.