Skip to content

Commit

Permalink
Merge pull request #364 from KxSystems/ee-selection
Browse files Browse the repository at this point in the history
Implement expand selection command
  • Loading branch information
ecmel authored Jun 25, 2024
2 parents cb21ed5 + 0c7ed02 commit e8619c4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ All notable changes to the **kdb VS Code extension** are documented in this file
- Extension changes scratchpad endpoints accordly to the Insights versions
- Allow connection information in user settings to be editable
- Allow same server address to be used in multiple connections
- Language server features works on unsaved files
- Expand Selection command is implemented

### Fixes

Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,14 @@ Set the following properties:

Set the following from the Advanced properties if necessary:

| Property | Description |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| Define Realm | Specify the Keycloak realm for authentication. Usually the realm is set to `insights`, which is the default value used by the extension. You only need to change this field if a different realm has been configured on your server. |
| Property | Description |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Define Realm | Specify the Keycloak realm for authentication. Usually the realm is set to `insights`, which is the default value used by the extension. You only need to change this field if a different realm has been configured on your server. |

![connecttoinsights](https://github.com/KxSystems/kx-vscode/blob/main/img/insightsconnectionadvanced.png?raw=true)


!!!note "For kdb Insights Enterprise Free Trial instances"
The realm is configured as `insights-{URL}` where {URL} is the 10 digit code in the trial URL. For example: if your trial url is https://fstc83yi5b.ft1.cld.kx.com/ the realm should be `insights-fstc83yi5b`.

The realm is configured as `insights-{URL}` where {URL} is the 10 digit code in the trial URL. For example: if your trial url is https://fstc83yi5b.ft1.cld.kx.com/ the realm should be `insights-fstc83yi5b`.

1. Click **Create Connection** and the **kdb Insights Enterprise** connection appears under **CONNECTIONS** in the primary sidebar.

Expand Down Expand Up @@ -535,6 +533,16 @@ To update kdb VS Code settings, search for **kdb** from _Preferences_ > _Setting
}
```

### Double Click Selection

The following setting will change double click behaviour to select the whole identifier including dots:

```JSON
"[q]": {
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?"
}
```

## Shortcuts

### For Windows
Expand Down
20 changes: 20 additions & 0 deletions server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
Range,
ReferenceParams,
RenameParams,
SelectionRange,
SelectionRangeParams,
ServerCapabilities,
SymbolKind,
TextDocumentChangeEvent,
Expand Down Expand Up @@ -99,6 +101,7 @@ export default class QLangServer {
"kdb.qls.parameterCache",
this.onParameterCache.bind(this),
);
this.connection.onSelectionRanges(this.onSelectionRanges.bind(this));
}

public capabilities(): ServerCapabilities {
Expand All @@ -109,6 +112,7 @@ export default class QLangServer {
definitionProvider: true,
renameProvider: true,
completionProvider: { resolveProvider: false },
selectionRangeProvider: true,
};
}

Expand Down Expand Up @@ -280,6 +284,22 @@ export default class QLangServer {
};
}

public onSelectionRanges({
textDocument,
positions,
}: SelectionRangeParams): SelectionRange[] {
const tokens = this.parse(textDocument);
const ranges: SelectionRange[] = [];

for (const position of positions) {
const source = positionToToken(tokens, position);
if (source) {
ranges.push(SelectionRange.create(rangeFromToken(source)));
}
}
return ranges;
}

private parse(textDocument: TextDocumentIdentifier): Token[] {
const document = this.documents.get(textDocument.uri);
if (!document) {
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export async function activate(context: ExtensionContext) {
},
};
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: "file", language: "q" }],
documentSelector: [{ language: "q" }],
synchronize: {
fileEvents: workspace.createFileSystemWatcher("**/*.{q,quke}"),
},
Expand Down
15 changes: 15 additions & 0 deletions test/suite/qLangServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe("qLangServer", () => {
onCompletion() {},
onDidChangeConfiguration() {},
onRequest() {},
onSelectionRanges() {},
});

const params = <InitializeParams>{
Expand All @@ -78,6 +79,7 @@ describe("qLangServer", () => {
assert.ok(capabilities.definitionProvider);
assert.ok(capabilities.renameProvider);
assert.ok(capabilities.completionProvider);
assert.ok(capabilities.selectionRangeProvider);
});
});

Expand Down Expand Up @@ -315,4 +317,17 @@ describe("qLangServer", () => {
assert.strictEqual(result, null);
});
});

describe("onSelectionRanges", () => {
it("should return identifier range", () => {
const params = createDocument(".test.ref");
const result = server.onSelectionRanges({
textDocument: params.textDocument,
positions: [params.position],
});
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].range.start.character, 0);
assert.strictEqual(result[0].range.end.character, 9);
});
});
});

0 comments on commit e8619c4

Please sign in to comment.