diff --git a/CHANGELOG.md b/CHANGELOG.md index 93b2f12..060c924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ All notable changes to the "vscode-vespa" extension will be documented in this file. + +## [1.0.1] + +- Minor bugfix for zipkin +- Fix keyboard shortcuts not clashing with vscode default shortcuts. + ## [1.0.0] - Initial release - diff --git a/README.md b/README.md index 056c00a..83c5063 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,4 @@ This is not enabled as the features it gives, at the moment, is limited. ## Release Notes -### 1.0.0 - -Initial release - ---- +Please read the [CHANGELOG](CHANGELOG.md) \ No newline at end of file diff --git a/client/package.json b/client/package.json index e291873..175a57b 100644 --- a/client/package.json +++ b/client/package.json @@ -3,7 +3,7 @@ "description": "VSCode part of a language server", "author": "Matti Pehrs", "license": "MIT", - "version": "1.0.0", + "version": "1.0.1", "publisher": "pehrs.com", "engines": { "vscode": "^1.75.0" diff --git a/client/src/extension.ts b/client/src/extension.ts index 7a4e628..4094b0e 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -34,6 +34,8 @@ export function activate(context: ExtensionContext) { registerRunQueryCommand(context); registerFormatterCommand(context); + registerYqlFormatter(context); + // NOT Needed yet as we are not saving the result state anywhere // Results panel view // if (vscode.window.registerWebviewPanelSerializer) { @@ -231,11 +233,13 @@ function registerRunQueryCommand(context: ExtensionContext) { const editor = vscode.window.activeTextEditor; + outputChannel.appendLine(`file: ${editor.document.fileName}`); + const workbenchConfig = vscode.workspace.getConfiguration('vespaYql'); const queryEndpoint: string = workbenchConfig.get('queryEndpoint'); const queryTimeout: string = workbenchConfig.get('queryTimeout'); - if (editor) { + if (editor && editor.document.fileName.endsWith(".yql")) { const document = editor.document; // Get the document text const yql = document.getText(); @@ -247,38 +251,60 @@ function registerRunQueryCommand(context: ExtensionContext) { } -function registerFormatterCommand(context: ExtensionContext) { - const runYqlCommand = vscode.commands.registerCommand('vscode-vespa.format', () => { +function registerYqlFormatter(context: ExtensionContext) { + vscode.languages.registerDocumentFormattingEditProvider('yql', { + provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] { - const editor = vscode.window.activeTextEditor; + formatYql(); + + // const firstLine = document.lineAt(0); + // if (firstLine.text !== '42') { + // return [vscode.TextEdit.insert(firstLine.range.start, '42\n')]; + // } + return []; + } + }); +} - if (editor) { - try { - const document = editor.document; - // Get the document text - const yql = document.getText(); - - const jsonObj = JSON.parse(yql); - const newYql = JSON.stringify(jsonObj, null, 2); - - const start = new vscode.Position(0, 0); - const lastLine = document.lineCount - 1; - const end = new vscode.Position(lastLine, document.lineAt(lastLine).text.length); - const allText = new vscode.Range(start, end); - - const edit = new vscode.WorkspaceEdit(); - edit.replace(document.uri, allText, newYql); - // edit.insert(document.uri, firstLine.range.start, '42\n'); - - return vscode.workspace.applyEdit(edit); - } catch (e) { - if (typeof e === "string") { - showError(e); - } else if (e instanceof Error) { - showError(e.message); - } + +function formatYql() { + const editor = vscode.window.activeTextEditor; + + outputChannel.appendLine(`format ${editor.document.fileName}`); + + if (editor && editor.document.fileName.endsWith(".yql")) { + try { + const document = editor.document; + // Get the document text + const yql = document.getText(); + + const jsonObj = JSON.parse(yql); + const newYql = JSON.stringify(jsonObj, null, 2); + + const start = new vscode.Position(0, 0); + const lastLine = document.lineCount - 1; + const end = new vscode.Position(lastLine, document.lineAt(lastLine).text.length); + const allText = new vscode.Range(start, end); + + const edit = new vscode.WorkspaceEdit(); + edit.replace(document.uri, allText, newYql); + // edit.insert(document.uri, firstLine.range.start, '42\n'); + + return vscode.workspace.applyEdit(edit); + } catch (e) { + if (typeof e === "string") { + showError(e); + } else if (e instanceof Error) { + showError(e.message); } } + } +} + +function registerFormatterCommand(context: ExtensionContext) { + const runYqlCommand = vscode.commands.registerCommand('vscode-vespa.format', () => { + + formatYql(); }); context.subscriptions.push(runYqlCommand); } @@ -709,8 +735,8 @@ class YqlResultsPanel { // TRACE if (this.zipkinLink !== undefined) { result += `

`; - result += `

Open in browser...

`; - result += `
`; + result += `

Open in browser...

`; + result += `
`; result += `

`; } @@ -745,12 +771,12 @@ class YqlResultsPanel { // Enable the iframe to load the zipkin url let cspUrl = "http://127.0.0.1:9411 http://localhost:9411"; - if(this.zipkinLink !== undefined) { + if (this.zipkinLink !== undefined) { const url = new URL(this.zipkinLink); cspUrl = `${url.protocol}//${url.host}`; - if(url.hostname === "localhost") { + if (url.hostname === "localhost") { cspUrl = `${url.protocol}//127.0.0.1:${url.port} ${cspUrl}`; - } + } } // outputChannel.appendLine(`cspUrl: ${cspUrl}`); diff --git a/client/testFixture/test.json b/client/testFixture/test.json new file mode 100644 index 0000000..a56519a --- /dev/null +++ b/client/testFixture/test.json @@ -0,0 +1,3 @@ +{ + "json": "sample" +} diff --git a/client/testFixture/test.yql b/client/testFixture/test.yql index f0a10d0..a71511f 100644 --- a/client/testFixture/test.yql +++ b/client/testFixture/test.yql @@ -1,18 +1,18 @@ { - "yql": "select title, url from msmarco where true limit 100", - "offset": 5, - "ranking": { - "matchPhase": { - "ascending": true, - "maxHits": 15 - } - }, - "presentation" : { - "bolding": false, - "format": "json" - }, - "trace": { - "level": 4, - "timestamps": true - } + "yql": "select title, url from msmarco where true limit 100", + "offset": 5, + "ranking": { + "matchPhase": { + "ascending": true, + "maxHits": 15 + } + }, + "presentation": { + "bolding": false, + "format": "json" + }, + "trace": { + "level": 4, + "timestamps": true + } } \ No newline at end of file diff --git a/package.json b/package.json index 4fd7c18..5867519 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-vespa", "displayName": "vscode-vespa", "description": "Vespa AI Extension", - "version": "1.0.0", + "version": "1.0.1", "publisher": "pehrs-com", "license": "SEE LICENSE IN LICENSE", "icon": "media/vespa.png", @@ -41,13 +41,9 @@ "keybindings": [ { "command": "vscode-vespa.runQuery", + "when": "editorLangId == yql", "key": "ctrl+enter", "mac": "cmd+enter" - }, - { - "command": "vscode-vespa.format", - "key": "ctrl+shift+i", - "mac": "cmd+shift-i" } ], "menus": { @@ -68,11 +64,6 @@ "when": "resourceLangId == yql", "command": "vscode-vespa.runQuery", "group": "navigation" - }, - { - "when": "resourceLangId == yql", - "command": "vscode-vespa.format", - "group": "navigation" } ] }, @@ -155,4 +146,4 @@ "dependencies": { "node-fetch": "^3.3.2" } -} +} \ No newline at end of file diff --git a/server/package.json b/server/package.json index 00d6650..e681eaf 100644 --- a/server/package.json +++ b/server/package.json @@ -1,7 +1,7 @@ { "name": "vscode-vespa-server", "description": "Example implementation of a language server in node.", - "version": "1.0.0", + "version": "1.0.1", "author": "Matti Pehrs", "license": "MIT", "engines": {