Skip to content

Commit

Permalink
fixed windows bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Oct 7, 2024
1 parent 767e5ba commit 8e45d0b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to the **kdb VS Code extension** are documented in this file

### Enhancements

- Add ability to add multiple labels to a single connection
- Show KDB+ process explorer item content when clicked
- Add ability to export and import connections
- All files in the workspace are considered when using language server features
Expand Down
80 changes: 44 additions & 36 deletions server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
TextEdit,
WorkspaceEdit,
} from "vscode-languageserver/node";
import { glob } from "glob";
import { sync as glob } from "glob";
import { fileURLToPath, pathToFileURL } from "node:url";
import {
FindKind,
Expand All @@ -73,7 +73,7 @@ import {
RCurly,
} from "./parser";
import { lint } from "./linter";
import { readFile } from "node:fs";
import { readFileSync } from "node:fs";

interface Settings {
debug: boolean;
Expand Down Expand Up @@ -168,16 +168,20 @@ export default class QLangServer {

/* istanbul ignore next */
public onDidChangeWatchedFiles({ changes }: DidChangeWatchedFilesParams) {
this.parseFiles(
changes.reduce((matches, change) => {
if (change.type === FileChangeType.Deleted) {
this.cached.delete(change.uri);
} else {
matches.push(fileURLToPath(change.uri));
}
return matches;
}, [] as string[]),
);
try {
this.parseFiles(
changes.reduce((matches, change) => {
if (change.type === FileChangeType.Deleted) {
this.cached.delete(change.uri);
} else {
matches.push(fileURLToPath(change.uri));
}
return matches;
}, [] as string[]),
);
} catch (error) {
this.connection.window.showErrorMessage(`${error}`);
}
}

public onDidChangeContent({
Expand Down Expand Up @@ -443,32 +447,33 @@ export default class QLangServer {

/* istanbul ignore next */
public scan() {
this.connection.workspace.getWorkspaceFolders().then((folders) => {
if (folders) {
folders.forEach((folder) => {
glob(
"**/*.{q,quke}",
{ cwd: fileURLToPath(folder.uri), ignore: "node_modules/**" },
(err, matches) => {
if (!err) {
this.parseFiles(matches);
}
},
const folders = this.params.workspaceFolders;
if (folders) {
try {
for (const folder of folders) {
this.parseFiles(
glob("**/*.{q,quke}", {
dot: true,
absolute: true,
nodir: true,
follow: false,
ignore: "node_modules/**/*.*",
cwd: fileURLToPath(folder.uri),
}),
);
});
}
} catch (error) {
this.connection.window.showErrorMessage(`${error}`);
}
});
}
}

/* istanbul ignore next */
private parseFiles(matches: string[]) {
matches.forEach((match) =>
readFile(match, "utf-8", (err, file) => {
if (!err) {
this.cached.set(pathToFileURL(match).toString(), parse(file));
}
}),
);
for (const match of matches) {
const file = readFileSync(match, "utf-8");
this.cached.set(pathToFileURL(match).toString(), parse(file));
}
}

private parse(textDocument: TextDocumentIdentifier): Token[] {
Expand All @@ -482,10 +487,13 @@ export default class QLangServer {
private context({ uri, tokens }: Tokenized, all = true): Tokenized[] {
if (all) {
this.documents.all().forEach((document) => {
this.cached.set(
document.uri,
document.uri === uri ? tokens : parse(document.getText()),
);
const path = fileURLToPath(document.uri);
if (path) {
this.cached.set(
pathToFileURL(path).toString(),
document.uri === uri ? tokens : parse(document.getText()),
);
}
});
return Array.from(this.cached.entries(), (entry) => ({
uri: entry[0],
Expand Down
2 changes: 2 additions & 0 deletions test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ describe("qLangServer", () => {
.stub(connection.workspace, "getWorkspaceFolders")
.value(async () => []);
server.scan();
assert.strictEqual(server["cached"].size, 0);
});
});

Expand All @@ -413,6 +414,7 @@ describe("qLangServer", () => {
.stub(connection.workspace, "getWorkspaceFolders")
.value(async () => []);
server.onDidChangeWatchedFiles({ changes: [] });
assert.strictEqual(server["cached"].size, 0);
});
});
});

0 comments on commit 8e45d0b

Please sign in to comment.