Skip to content

Commit

Permalink
fix for correct semantic highlights and correcting parameters in work…
Browse files Browse the repository at this point in the history
…space
  • Loading branch information
diyaayay committed May 21, 2024
1 parent a2e5ea8 commit befa79c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion language-server/src/features/semantic-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getSchemaDocument } from "./schema-documents.js";
import { toAbsoluteUri } from "../util.js";
import { schemaFilePatterns } from "./document-settings.js";
import { isMatchedFile } from "./workspace.js";
import { fileURLToPath } from "node:url";


export default {
Expand Down Expand Up @@ -52,7 +53,8 @@ export default {
};

connection.languages.semanticTokens.on(async ({ textDocument }) => {
if (!isMatchedFile(textDocument.uri, schemaFilePatterns)) {
const filePath = fileURLToPath(textDocument.uri);
if (!isMatchedFile(filePath, schemaFilePatterns)) {
return { data: [] };
}

Expand Down
11 changes: 6 additions & 5 deletions language-server/src/features/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
import { TextDocument } from "vscode-languageserver-textdocument";
import { publish, publishAsync, subscribe } from "../pubsub.js";
import { getSchemaDocument } from "./schema-documents.js";
import { getDocumentSettings } from "./document-settings.js";
import { getDocumentSettings, schemaFilePatterns } from "./document-settings.js";
import picomatch from "picomatch";


export const isMatchedFile = (uri, patterns) => {
patterns = patterns.map((pattern) => `**/${pattern}`);
const matchers = patterns.map((pattern) => {
return picomatch(pattern, {
noglobstar: false,
Expand Down Expand Up @@ -126,7 +127,7 @@ export default {
]
});
} else {
watchWorkspace(onWorkspaceChange, isMatchedFile);
watchWorkspace(onWorkspaceChange);
}

if (hasWorkspaceFolderCapability) {
Expand All @@ -135,7 +136,7 @@ export default {
removeWorkspaceFolders(removed);

if (!hasWorkspaceWatchCapability) {
watchWorkspace(onWorkspaceChange, isMatchedFile);
watchWorkspace(onWorkspaceChange, schemaFilePatterns);
}

publish("workspaceChanged", { changes: [] });
Expand Down Expand Up @@ -176,7 +177,7 @@ const removeWorkspaceFolders = (folders) => {

const watchers = {};

const watchWorkspace = (handler, isSchema) => {
const watchWorkspace = (handler, schemaFilePatterns) => {
for (const { uri } of workspaceFolders) {
const path = fileURLToPath(uri);

Expand All @@ -185,7 +186,7 @@ const watchWorkspace = (handler, isSchema) => {
}

watchers[path] = watch(path, { recursive: true }, (eventType, filename) => {
if (isSchema(filename)) {
if (isMatchedFile(filename, schemaFilePatterns)) {
handler(eventType, filename);
}
});
Expand Down

0 comments on commit befa79c

Please sign in to comment.