From ad523e8341aecec4591f1608b0f8abef75db4dbd Mon Sep 17 00:00:00 2001 From: zalan_racz Date: Thu, 18 Jan 2024 18:19:11 +0100 Subject: [PATCH 1/6] Fixing an incorrect condition about making the language server executable in Linux and Mac --- Dagor-Shader-Language-Server | 2 +- src/client-desktop.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dagor-Shader-Language-Server b/Dagor-Shader-Language-Server index 261440f..e4144a8 160000 --- a/Dagor-Shader-Language-Server +++ b/Dagor-Shader-Language-Server @@ -1 +1 @@ -Subproject commit 261440f90e0aa5a6301d92e8e6588500233803b3 +Subproject commit e4144a8eae28df12a538cffaf180aa0ed7788099 diff --git a/src/client-desktop.ts b/src/client-desktop.ts index 8d95f52..d8380fc 100644 --- a/src/client-desktop.ts +++ b/src/client-desktop.ts @@ -59,7 +59,7 @@ function getExecutableFileName(): string { } async function makeFileExecutableIfNeeded(file: string): Promise { - if (os.platform() !== 'win32') { + if (os.platform() === 'win32') { return true; } try { From 96c611f8862e2878851339c8ad31c223a360566d Mon Sep 17 00:00:00 2001 From: zalan_racz Date: Thu, 25 Jan 2024 13:11:37 +0100 Subject: [PATCH 2/6] Adding a context menu item to the shader config files to make shader config overriding easier --- Dagor-Shader-Language-Server | 2 +- package.json | 22 +++++++++++++++++++++- src/client-desktop.ts | 34 ++++++++++++++++++++++++++++------ src/constant.ts | 4 ++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/Dagor-Shader-Language-Server b/Dagor-Shader-Language-Server index e4144a8..0504967 160000 --- a/Dagor-Shader-Language-Server +++ b/Dagor-Shader-Language-Server @@ -1 +1 @@ -Subproject commit e4144a8eae28df12a538cffaf180aa0ed7788099 +Subproject commit 0504967cf9e7dbabd82db74aaef7286a8009a501 diff --git a/package.json b/package.json index f24f33a..9813426 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,27 @@ } } } - ] + ], + "commands": [ + { + "command": "dagorShaderLanguageServer.setShaderConfig", + "title": "Set as shader config override" + } + ], + "menus": { + "commandPalette": [ + { + "command": "dagorShaderLanguageServer.setShaderConfig", + "when": "false" + } + ], + "explorer/context": [ + { + "when": "resourceLangId == blk && resourceFilename =~ /shaders_.*?\\.blk$/", + "command": "dagorShaderLanguageServer.setShaderConfig" + } + ] + } }, "main": "./out/client-desktop", "browser": "./out/client-web", diff --git a/src/client-desktop.ts b/src/client-desktop.ts index d8380fc..2da3a7c 100644 --- a/src/client-desktop.ts +++ b/src/client-desktop.ts @@ -1,7 +1,13 @@ -import { ExtensionContext, ExtensionMode } from 'vscode'; +import { ExtensionContext, ExtensionMode, Uri, commands, window, workspace } from 'vscode'; import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node'; -import { EXTENSION_ID, EXTENSION_NAME } from './constant'; +import { + COMMAND_ID_SET_SHADER_CONFIG, + CONFIGURATION_ID_SHADER_CONFIG_OVERRIDE, + EXTENSION_ID, + EXTENSION_NAME, + LANGUAGE_SERVER_ID, +} from './constant'; import * as fsp from 'fs/promises'; import * as os from 'os'; @@ -10,6 +16,26 @@ import * as path from 'path'; let client: LanguageClient; export async function activate(context: ExtensionContext): Promise { + addCommands(context); + startServer(context); +} + +export function deactivate(): Thenable | undefined { + return client?.stop(); +} + +function addCommands(context: ExtensionContext): void { + context.subscriptions.push( + commands.registerCommand(COMMAND_ID_SET_SHADER_CONFIG, async (uri: Uri) => { + await workspace + .getConfiguration(LANGUAGE_SERVER_ID) + .update(CONFIGURATION_ID_SHADER_CONFIG_OVERRIDE, workspace.asRelativePath(uri)); + await window.showInformationMessage('Shader config override changed'); + }) + ); +} + +async function startServer(context: ExtensionContext): Promise { const serverOptions = await getServerOptions(context); const clientOptions: LanguageClientOptions = { documentSelector: [{ language: 'dshl' }, { language: 'hlsl' }], @@ -19,10 +45,6 @@ export async function activate(context: ExtensionContext): Promise { client.start(); } -export function deactivate(): Thenable | undefined { - return client?.stop(); -} - async function getServerOptions(context: ExtensionContext): Promise { if (context.extensionMode === ExtensionMode.Production && isExecutableAvailable()) { const executablePath = getExecutablePath(context); diff --git a/src/constant.ts b/src/constant.ts index fbc7368..05eca79 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,3 +1,7 @@ export const EXTENSION_ID = 'dagor-shader-language-support'; export const EXTENSION_NAME = 'Dagor Shader Language Support'; export const EXTENSION_PUBLISHER = 'gaijin'; + +export const LANGUAGE_SERVER_ID = 'dagorShaderLanguageServer'; +export const COMMAND_ID_SET_SHADER_CONFIG = `${LANGUAGE_SERVER_ID}.setShaderConfig`; +export const CONFIGURATION_ID_SHADER_CONFIG_OVERRIDE = 'shaderConfigOverride'; From 4e06bcbab3c76d342c7a50b8f002edb663db0fab Mon Sep 17 00:00:00 2001 From: zalan_racz Date: Thu, 25 Jan 2024 13:22:23 +0100 Subject: [PATCH 3/6] Fixing the inlay hints test --- src/test/inlay-hint.test.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/test/inlay-hint.test.ts b/src/test/inlay-hint.test.ts index 177bfb4..e30147e 100644 --- a/src/test/inlay-hint.test.ts +++ b/src/test/inlay-hint.test.ts @@ -2,20 +2,13 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; import { activate } from './helper'; -import { - MacroUsage, - macroWithParametersUsage, - macroWithWrongNumberOfParametersUsage, - strangeMacroUsage, - testMacroFileUri, -} from './macro-helper'; +import { MacroUsage, macroWithParametersUsage, strangeMacroUsage, testMacroFileUri } from './macro-helper'; suite('Inlay hints in .dshl files', () => { test('should show inlay hints for DSHL macro arguments', async () => { await activate(testMacroFileUri); await openDocumentAndAssertInlayHints([ ...getInlayHints(macroWithParametersUsage), - ...getInlayHints(macroWithWrongNumberOfParametersUsage), ...getInlayHints(strangeMacroUsage), ]); }); @@ -40,7 +33,8 @@ async function openDocumentAndAssertInlayHints(expectedItems: vscode.InlayHint[] assert.equal(expectedItems.length, actualItems.length); expectedItems.forEach((expectedItem, i) => { const actualItem = actualItems[i]; - assert.equal(expectedItem.label, actualItem.label); + const actualLabel = actualItem.label[0] as vscode.InlayHintLabelPart; + assert.equal(expectedItem.label, actualLabel.value); assert.ok(expectedItem.position?.isEqual(actualItem.position!)); assert.equal(expectedItem.kind, actualItem.kind); assert.equal(expectedItem.paddingLeft, actualItem.paddingLeft); From f5c2972ff20dcf567ed27449d72916579c932865 Mon Sep 17 00:00:00 2001 From: zalan_racz Date: Thu, 25 Jan 2024 17:23:10 +0100 Subject: [PATCH 4/6] Making the shader config override context menu only appear in desktop mode --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9813426..87730de 100644 --- a/package.json +++ b/package.json @@ -104,8 +104,8 @@ ], "explorer/context": [ { - "when": "resourceLangId == blk && resourceFilename =~ /shaders_.*?\\.blk$/", - "command": "dagorShaderLanguageServer.setShaderConfig" + "command": "dagorShaderLanguageServer.setShaderConfig", + "when": "!isWeb && resourceFilename =~ /shaders_.*?\\.blk$/" } ] } From 0862f129ba516632ec7eb5e0db029147cc4b9c7f Mon Sep 17 00:00:00 2001 From: zalan_racz Date: Thu, 25 Jan 2024 17:37:12 +0100 Subject: [PATCH 5/6] Making the browser open the test files as a workspace instead of the whole project --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87730de..e7a4f6e 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "package-all": "start npm run package-universal & start npm run package-windows-x64 & start npm run package-macos-x64 & start npm run package-linux-x64", "build-tests": "tsc -p ./tsconfig.test.json", "watch-tests": "tsc -w -p ./tsconfig.test.json", - "open-in-browser": "vscode-test-web --extensionDevelopmentPath=. .", + "open-in-browser": "vscode-test-web --extensionDevelopmentPath=. ./testFixture", "eslint": "eslint ./src ./Dagor-Shader-Language-Server/src --ext .ts", "prettier-lint": "prettier --check .", "prettier-format": "prettier --write .", From e74974be427bc33dabc5f31b7df8604bce67ccd4 Mon Sep 17 00:00:00 2001 From: zalan_racz Date: Thu, 25 Jan 2024 19:57:53 +0100 Subject: [PATCH 6/6] Updating the language server --- Dagor-Shader-Language-Server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dagor-Shader-Language-Server b/Dagor-Shader-Language-Server index 0504967..44739df 160000 --- a/Dagor-Shader-Language-Server +++ b/Dagor-Shader-Language-Server @@ -1 +1 @@ -Subproject commit 0504967cf9e7dbabd82db74aaef7286a8009a501 +Subproject commit 44739df315f1caeb7483e5e8a906e3d84ab8970b