Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #6

Merged
merged 6 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dagor-Shader-Language-Server
Submodule Dagor-Shader-Language-Server updated 37 files
+2 −0 src/core/capability-manager.ts
+0 −1 src/core/debug.ts
+85 −30 src/core/snapshot.ts
+0 −4 src/helper/file-helper.ts
+3 −0 src/helper/helper.ts
+0 −111 src/helper/performance-helper.ts
+1 −0 src/interface/capabilities.ts
+1 −1 src/interface/hlsl-block.ts
+0 −1 src/interface/host-dependent.ts
+0 −11 src/interface/macro/macro-context-base.ts
+3 −5 src/interface/macro/macro-context.ts
+36 −0 src/interface/macro/macro-declaration.ts
+8 −0 src/interface/macro/macro-parameter-usage.ts
+8 −0 src/interface/macro/macro-parameter.ts
+0 −23 src/interface/macro/macro-statement.ts
+52 −0 src/interface/macro/macro-usage.ts
+25 −0 src/interface/macro/macro.ts
+6 −0 src/processor/condition-visitor.ts
+288 −164 src/processor/dshl-preprocessor.ts
+2 −21 src/processor/hlsl-preprocessor.ts
+0 −5 src/processor/include-processor.ts
+84 −2 src/processor/include-resolver.ts
+2 −18 src/processor/preprocessor.ts
+44 −18 src/provider/completion-provider.ts
+55 −24 src/provider/document-highlight-provider.ts
+1 −7 src/provider/document-link-resolve-provider.ts
+0 −5 src/provider/document-links-provider.ts
+19 −15 src/provider/document-symbol-provider.ts
+3 −3 src/provider/folding-ranges-provider.ts
+14 −13 src/provider/hover-provider.ts
+1 −1 src/provider/implementation-provider.ts
+27 −15 src/provider/inlay-hint-provider.ts
+58 −15 src/provider/link-provider-base.ts
+40 −19 src/provider/signature-help-provider.ts
+22 −2 src/server-desktop.ts
+0 −1 src/server-web.ts
+23 −18 src/server.ts
24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,27 @@
}
}
}
]
],
"commands": [
{
"command": "dagorShaderLanguageServer.setShaderConfig",
"title": "Set as shader config override"
}
],
"menus": {
"commandPalette": [
{
"command": "dagorShaderLanguageServer.setShaderConfig",
"when": "false"
}
],
"explorer/context": [
{
"command": "dagorShaderLanguageServer.setShaderConfig",
"when": "!isWeb && resourceFilename =~ /shaders_.*?\\.blk$/"
}
]
}
},
"main": "./out/client-desktop",
"browser": "./out/client-web",
Expand All @@ -103,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 .",
Expand Down
36 changes: 29 additions & 7 deletions src/client-desktop.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,6 +16,26 @@ import * as path from 'path';
let client: LanguageClient;

export async function activate(context: ExtensionContext): Promise<void> {
addCommands(context);
startServer(context);
}

export function deactivate(): Thenable<void> | 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<void> {
const serverOptions = await getServerOptions(context);
const clientOptions: LanguageClientOptions = {
documentSelector: [{ language: 'dshl' }, { language: 'hlsl' }],
Expand All @@ -19,10 +45,6 @@ export async function activate(context: ExtensionContext): Promise<void> {
client.start();
}

export function deactivate(): Thenable<void> | undefined {
return client?.stop();
}

async function getServerOptions(context: ExtensionContext): Promise<ServerOptions> {
if (context.extensionMode === ExtensionMode.Production && isExecutableAvailable()) {
const executablePath = getExecutablePath(context);
Expand Down Expand Up @@ -59,7 +81,7 @@ function getExecutableFileName(): string {
}

async function makeFileExecutableIfNeeded(file: string): Promise<boolean> {
if (os.platform() !== 'win32') {
if (os.platform() === 'win32') {
return true;
}
try {
Expand Down
4 changes: 4 additions & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -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';
12 changes: 3 additions & 9 deletions src/test/inlay-hint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
});
Expand All @@ -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);
Expand Down