Skip to content

Commit

Permalink
Merge pull request #451 from KxSystems/ee-fixes
Browse files Browse the repository at this point in the history
[LS] More coverage and fixes
  • Loading branch information
ecmel authored Nov 7, 2024
2 parents 47bd144 + cfd2063 commit 91f5c58
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ All notable changes to the **kdb VS Code extension** are documented in this file
### Enhancements

- Semantic highlighting for local variables
- Display version of Insights server connected
- Display version of connected Insights server

### Fixes

- Fix for results tab flickering , improving of UX
- Fix for Issue [#382](https://github.com/KxSystems/kx-vscode/issues/382)
- Fix for run q file not using the current editor contents
- Fix for autocomplete for new and unsaved documents
- Fix for results tab

### Internal Improvements

Expand Down
8 changes: 2 additions & 6 deletions server/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ function assignment(state: State, token: Token) {
if (top?.tokenType === Colon || top?.tokenType === DoubleColon) {
token.assignment = [top];
stack.pop();
top = stack.shift();
if (top) {
token.assignment.push(top);
if (stack.length > 0) {
token.assignment.push(...stack);
clear(stack);
}
}
Expand Down Expand Up @@ -182,9 +181,6 @@ function expression(state: State, tokens: Token[]) {
break;
}
break;
case RParen:
case LParen:
break;
default:
stack.push(token);
break;
Expand Down
3 changes: 3 additions & 0 deletions server/src/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export function amended(token: Token) {
}

export function local(token: Token, tokens: Token[]) {
if (qualified(token)) {
return false;
}
const scope = inLambda(token);
if (scope && !scope.tangled) {
if (token.image === "x" || token.image === "y" || token.image === "z") {
Expand Down
2 changes: 1 addition & 1 deletion server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default class QLangServer {

public setSettings(settings: LSPAny) {
this.settings = {
debug: settings.debug || false,
debug: settings.debug_parser || false,
linting: settings.linting || false,
refactoring: settings.refactoring || "Workspace",
};
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand(
"kdb.createDataSource",
async (item: FileTreeItem) => {
if (hasWorkspaceOrShowOption()) {
if (hasWorkspaceOrShowOption("adding datasources")) {
const uri = await addWorkspaceFile(item, "datasource", ".kdb.json");

if (uri) {
Expand Down Expand Up @@ -501,7 +501,7 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand(
"kdb.createScratchpad",
async (item: FileTreeItem) => {
if (hasWorkspaceOrShowOption()) {
if (hasWorkspaceOrShowOption("adding workbooks")) {
const uri = await addWorkspaceFile(item, "workbook", ".kdb.q");
if (uri) {
await window.showTextDocument(uri);
Expand All @@ -513,7 +513,7 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand(
"kdb.createPythonScratchpad",
async (item: FileTreeItem) => {
if (hasWorkspaceOrShowOption()) {
if (hasWorkspaceOrShowOption("adding workbooks")) {
const uri = await addWorkspaceFile(item, "workbook", ".kdb.py");
if (uri) {
await window.showTextDocument(uri);
Expand Down
7 changes: 5 additions & 2 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,15 @@ export function formatTable(headers_: any, rows_: any, opts: any) {
return result.join("\n");
}

export function hasWorkspaceOrShowOption() {
export function hasWorkspaceOrShowOption(action: string) {
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
return true;
}
window
.showWarningMessage("No workspace folder is opened.", "Open")
.showWarningMessage(
`No workspace folder is open. Please open a folder to enable ${action}.`,
"Open",
)
.then((res) => {
if (res === "Open") {
commands.executeCommand("workbench.action.files.openFolder");
Expand Down
14 changes: 13 additions & 1 deletion test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,23 @@ describe("qLangServer", () => {
});

describe("onSemanticTokens", () => {
it("should find semantic local variables", () => {
it("should tokenize local variables", () => {
const params = createDocument("a:{[b;c]d:1;b*c*d}");
const result = server.onSemanticTokens(params);
assert.strictEqual(result.data.length, 30);
});

it("should ignore qualified variables", () => {
const params = createDocument("a:{.ns.b:1;.ns.b}");
const result = server.onSemanticTokens(params);
assert.strictEqual(result.data.length, 0);
});

it("should detect empty lists", () => {
const params = createDocument("a:{b:();b}");
const result = server.onSemanticTokens(params);
assert.strictEqual(result.data.length, 10);
});
});

describe("setSettings", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,13 @@ describe("Utils", () => {

it("should return true if a workspace folder is opened", () => {
sinon.stub(vscode.workspace, "workspaceFolders").get(() => [{}]);
const result = coreUtils.hasWorkspaceOrShowOption();
const result = coreUtils.hasWorkspaceOrShowOption("Test");
assert.strictEqual(result, true);
});

it("should return false and display message if no workspace", () => {
const stub = sinon.stub(vscode.window, "showWarningMessage").resolves();
const result = coreUtils.hasWorkspaceOrShowOption();
const result = coreUtils.hasWorkspaceOrShowOption("Test");
assert.strictEqual(result, false);
assert.ok(stub.calledOnce);
});
Expand Down

0 comments on commit 91f5c58

Please sign in to comment.