Skip to content

Commit

Permalink
Merge pull request #4 from GaijinEntertainment/improvements
Browse files Browse the repository at this point in the history
General improvements
  • Loading branch information
zalan-racz-gaijin authored Jan 16, 2024
2 parents b884642 + 77ea5e2 commit 0ae351d
Show file tree
Hide file tree
Showing 22 changed files with 132 additions and 356 deletions.
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"printWidth": 120,
"endOfLine": "lf",
"useTabs": false,
"tabWidth": 4,
Expand Down
9 changes: 2 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
"type": "extensionHost",
"request": "launch",
"debugWebWorkerHost": true,
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionDevelopmentKind=web"
],
"args": ["--extensionDevelopmentPath=${workspaceFolder}", "--extensionDevelopmentKind=web"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": {
"type": "npm",
Expand All @@ -36,9 +33,7 @@
"port": 6009,
"restart": true,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/Dagor-Shader-Language-Server/out/**/*.js"
]
"outFiles": ["${workspaceFolder}/Dagor-Shader-Language-Server/out/**/*.js"]
},
{
"name": "Run E2E Tests",
Expand Down
5 changes: 1 addition & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$ts-webpack-watch",
"$ts-checker-eslint-webpack-watch"
]
"problemMatcher": ["$ts-webpack-watch", "$ts-checker-eslint-webpack-watch"]
},
{
"label": "Build Tests",
Expand Down
2 changes: 1 addition & 1 deletion Dagor-Shader-Language-Server
Submodule Dagor-Shader-Language-Server updated 44 files
+1 −0 .prettierrc.json
+0 −72 BUILD.md
+0 −14 CHANGELOG.md
+1 −1 LICENSE
+12 −6 README.md
+2 −2 grammar/dshl.tmLanguage.json
+1 −1 grammar/hlsl.tmLanguage.json
+16 −32 src/core/capability-manager.ts
+7 −25 src/core/configuration-manager.ts
+7 −18 src/core/document-info.ts
+29 −81 src/core/snapshot.ts
+48 −0 src/helper/dshl-info.ts
+2 −7 src/helper/file-helper.ts
+1 −4 src/helper/fs-helper.ts
+2 −4 src/helper/helper.ts
+413 −1,083 src/helper/hlsl-info.ts
+6 −16 src/helper/performance-helper.ts
+2 −5 src/interface/capabilities.ts
+0 −1 src/interface/configuration.ts
+1 −4 src/interface/macro/macro-statement.ts
+7 −13 src/interface/snippets.ts
+3 −16 src/processor/condition-visitor.ts
+38 −155 src/processor/dshl-preprocessor.ts
+2 −11 src/processor/hlsl-block-processor.ts
+67 −274 src/processor/hlsl-preprocessor.ts
+15 −64 src/processor/include-processor.ts
+9 −31 src/processor/include-resolver.ts
+8 −24 src/processor/macro-arguments-processor.ts
+16 −66 src/processor/preprocessor.ts
+47 −241 src/provider/completion-provider.ts
+2 −10 src/provider/declaration-provider.ts
+2 −10 src/provider/definition-provider.ts
+4 −14 src/provider/document-highlight-provider.ts
+3 −12 src/provider/document-links-provider.ts
+2 −9 src/provider/document-symbol-provider.ts
+4 −18 src/provider/folding-ranges-provider.ts
+4 −15 src/provider/hover-provider.ts
+2 −10 src/provider/implementation-provider.ts
+2 −8 src/provider/inlay-hint-provider.ts
+1 −6 src/provider/link-provider-base.ts
+3 −9 src/provider/signature-help-provider.ts
+13 −45 src/server-desktop.ts
+1 −2 src/server-web.ts
+5 −6 src/server.ts
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@
"pattern": ".*?shaders_(.*?)\\.blk|^$",
"patternErrorMessage": "The shader config file's name has to be shaders_<CONFIG>.blk.",
"markdownDescription": " Shader configs are .blk files, usually located in the games' `prog/shaders` folders, and they determine include folders. For example: `samples/testGI/prog/shaders/shaders_dx12.blk`. If you want to override the extension's automatic shader config selection, provide the shader config's path here. Leaving it empty enables the automatic selection based on game, platform, and driver in launch options."
},
"dagorShaderLanguageServer.folding": {
"type": "boolean",
"order": 1,
"default": false,
"description": "Enables/disables the language server's code folding. If disabled, VS Code's built-in code folding will be used instead."
}
}
}
Expand Down
36 changes: 7 additions & 29 deletions src/client-desktop.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { ExtensionContext, ExtensionMode } from 'vscode';
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind,
} from 'vscode-languageclient/node';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';

import { EXTENSION_ID, EXTENSION_NAME } from './constant';

Expand All @@ -19,12 +14,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
const clientOptions: LanguageClientOptions = {
documentSelector: [{ language: 'dshl' }, { language: 'hlsl' }],
};
client = new LanguageClient(
EXTENSION_ID,
EXTENSION_NAME,
serverOptions,
clientOptions
);
client = new LanguageClient(EXTENSION_ID, EXTENSION_NAME, serverOptions, clientOptions);

client.start();
}
Expand All @@ -33,13 +23,8 @@ export function deactivate(): Thenable<void> | undefined {
return client?.stop();
}

async function getServerOptions(
context: ExtensionContext
): Promise<ServerOptions> {
if (
context.extensionMode === ExtensionMode.Production &&
isExecutableAvailable()
) {
async function getServerOptions(context: ExtensionContext): Promise<ServerOptions> {
if (context.extensionMode === ExtensionMode.Production && isExecutableAvailable()) {
const executablePath = getExecutablePath(context);
const executable = await makeFileExecutableIfNeeded(executablePath);
if (executable) {
Expand All @@ -51,18 +36,13 @@ async function getServerOptions(

function isExecutableAvailable(): boolean {
return (
(os.platform() === 'win32' ||
os.platform() === 'linux' ||
os.platform() === 'darwin') &&
os.arch() === 'x64'
(os.platform() === 'win32' || os.platform() === 'linux' || os.platform() === 'darwin') && os.arch() === 'x64'
);
}

function getExecutablePath(context: ExtensionContext): string {
const fileName = getExecutableFileName();
return context.asAbsolutePath(
path.join('Dagor-Shader-Language-Server', 'bin', fileName)
);
return context.asAbsolutePath(path.join('Dagor-Shader-Language-Server', 'bin', fileName));
}

function getExecutableFileName(): string {
Expand Down Expand Up @@ -98,9 +78,7 @@ async function makeFileExecutableIfNeeded(file: string): Promise<boolean> {
}

function getNodeJsServerOptions(context: ExtensionContext): ServerOptions {
const serverModule = context.asAbsolutePath(
path.join('Dagor-Shader-Language-Server', 'out', 'server-desktop.js')
);
const serverModule = context.asAbsolutePath(path.join('Dagor-Shader-Language-Server', 'out', 'server-desktop.js'));
return {
run: {
module: serverModule,
Expand Down
12 changes: 2 additions & 10 deletions src/client-web.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { ExtensionContext, Uri } from 'vscode';
import {
LanguageClient,
LanguageClientOptions,
} from 'vscode-languageclient/browser';
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient/browser';

import { EXTENSION_ID, EXTENSION_NAME } from './constant';

Expand All @@ -22,12 +19,7 @@ export function activate(context: ExtensionContext) {

const worker = new Worker(serverModule);

client = new LanguageClient(
EXTENSION_ID,
EXTENSION_NAME,
clientOptions,
worker
);
client = new LanguageClient(EXTENSION_ID, EXTENSION_NAME, clientOptions, worker);

client.start();
}
8 changes: 2 additions & 6 deletions src/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ suite('Code completion in .dshl files', () => {
});
});

function getCompletionItems(
...mds: MacroDeclaration[]
): vscode.CompletionItem[] {
function getCompletionItems(...mds: MacroDeclaration[]): vscode.CompletionItem[] {
return mds.map((md) => ({
label: md.name,
kind: vscode.CompletionItemKind.Constant,
Expand Down Expand Up @@ -92,9 +90,7 @@ async function openDocumentAndAssertCompletionItems(
assert.equal(actualItem.detail, expectedItem.detail);
});
notExpectedItems.forEach((notExpectedItem) => {
const actualItem = actualItems.find(
(ai) => ai.label === notExpectedItem.label
);
const actualItem = actualItems.find((ai) => ai.label === notExpectedItem.label);
assert.ok(!actualItem);
});
}
57 changes: 14 additions & 43 deletions src/test/declaration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,9 @@ import {
suite('Go to declaration in .dshl files', () => {
test('should go to DSHL macro declarations', async () => {
await activate(testMacroFileUri);
await openDocumentAndAssertDeclaration(
testMacroCursorPosition,
getLocationLink(testMacroDeclaration)
);
await openDocumentAndAssertDeclaration(
testMacroStartCursorPosition,
getLocationLink(testMacroDeclaration)
);
await openDocumentAndAssertDeclaration(
testMacroEndCursorPosition,
getLocationLink(testMacroDeclaration)
);
await openDocumentAndAssertDeclaration(testMacroCursorPosition, getLocationLink(testMacroDeclaration));
await openDocumentAndAssertDeclaration(testMacroStartCursorPosition, getLocationLink(testMacroDeclaration));
await openDocumentAndAssertDeclaration(testMacroEndCursorPosition, getLocationLink(testMacroDeclaration));
await openDocumentAndAssertDeclaration(
macroWithoutContentCursorPosition,
getLocationLink(macroWithoutContentDeclaration)
Expand All @@ -52,18 +43,9 @@ suite('Go to declaration in .dshl files', () => {
macroWithWrongNumberOfParametersCursorPosition,
getLocationLink(macroWithWrongNumberOfParametersDeclaration)
);
await openDocumentAndAssertDeclaration(
optionalMacroCursorPosition,
getLocationLink(optionalMacroDeclaration)
);
await openDocumentAndAssertDeclaration(
macroWithoutDefinitionCursorPosition,
[]
);
await openDocumentAndAssertDeclaration(
strangeMacroCursorPosition,
getLocationLink(strangeMacroDeclaration)
);
await openDocumentAndAssertDeclaration(optionalMacroCursorPosition, getLocationLink(optionalMacroDeclaration));
await openDocumentAndAssertDeclaration(macroWithoutDefinitionCursorPosition, []);
await openDocumentAndAssertDeclaration(strangeMacroCursorPosition, getLocationLink(strangeMacroDeclaration));
await openDocumentAndAssertDeclaration(
macroFromAnotherFileCursorPosition,
getLocationLink(macroFromAnotherFileDeclaration)
Expand All @@ -76,28 +58,17 @@ async function openDocumentAndAssertDeclaration(
position: vscode.Position,
expectedItems: vscode.LocationLink[]
): Promise<void> {
const actualItems: vscode.LocationLink[] =
await vscode.commands.executeCommand(
'vscode.executeDeclarationProvider',
testMacroFileUri,
position
);
const actualItems: vscode.LocationLink[] = await vscode.commands.executeCommand(
'vscode.executeDeclarationProvider',
testMacroFileUri,
position
);
assert.equal(expectedItems.length, actualItems.length);
expectedItems.forEach((expectedItem, i) => {
const actualItem = actualItems[i];
assert.equal(
expectedItem.targetUri.fsPath,
actualItem.targetUri.fsPath
);
assert.equal(expectedItem.targetUri.fsPath, actualItem.targetUri.fsPath);
assert.ok(expectedItem.targetRange?.isEqual(actualItem.targetRange!));
assert.ok(
expectedItem.targetSelectionRange?.isEqual(
actualItem.targetSelectionRange!
)
);
assert.equal(
expectedItem.originSelectionRange,
actualItem.originSelectionRange
);
assert.ok(expectedItem.targetSelectionRange?.isEqual(actualItem.targetSelectionRange!));
assert.equal(expectedItem.originSelectionRange, actualItem.originSelectionRange);
});
}
57 changes: 14 additions & 43 deletions src/test/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,9 @@ import {
suite('Go to definition in .dshl files', () => {
test('should go to DSHL macro definitions', async () => {
await activate(testMacroFileUri);
await openDocumentAndAssertDefinition(
testMacroCursorPosition,
getLocationLink(testMacroDeclaration)
);
await openDocumentAndAssertDefinition(
testMacroStartCursorPosition,
getLocationLink(testMacroDeclaration)
);
await openDocumentAndAssertDefinition(
testMacroEndCursorPosition,
getLocationLink(testMacroDeclaration)
);
await openDocumentAndAssertDefinition(testMacroCursorPosition, getLocationLink(testMacroDeclaration));
await openDocumentAndAssertDefinition(testMacroStartCursorPosition, getLocationLink(testMacroDeclaration));
await openDocumentAndAssertDefinition(testMacroEndCursorPosition, getLocationLink(testMacroDeclaration));
await openDocumentAndAssertDefinition(
macroWithoutContentCursorPosition,
getLocationLink(macroWithoutContentDeclaration)
Expand All @@ -52,18 +43,9 @@ suite('Go to definition in .dshl files', () => {
macroWithWrongNumberOfParametersCursorPosition,
getLocationLink(macroWithWrongNumberOfParametersDeclaration)
);
await openDocumentAndAssertDefinition(
optionalMacroCursorPosition,
getLocationLink(optionalMacroDeclaration)
);
await openDocumentAndAssertDefinition(
macroWithoutDefinitionCursorPosition,
[]
);
await openDocumentAndAssertDefinition(
strangeMacroCursorPosition,
getLocationLink(strangeMacroDeclaration)
);
await openDocumentAndAssertDefinition(optionalMacroCursorPosition, getLocationLink(optionalMacroDeclaration));
await openDocumentAndAssertDefinition(macroWithoutDefinitionCursorPosition, []);
await openDocumentAndAssertDefinition(strangeMacroCursorPosition, getLocationLink(strangeMacroDeclaration));
await openDocumentAndAssertDefinition(
macroFromAnotherFileCursorPosition,
getLocationLink(macroFromAnotherFileDeclaration)
Expand All @@ -76,28 +58,17 @@ async function openDocumentAndAssertDefinition(
position: vscode.Position,
expectedItems: vscode.LocationLink[]
): Promise<void> {
const actualItems: vscode.LocationLink[] =
await vscode.commands.executeCommand(
'vscode.executeDefinitionProvider',
testMacroFileUri,
position
);
const actualItems: vscode.LocationLink[] = await vscode.commands.executeCommand(
'vscode.executeDefinitionProvider',
testMacroFileUri,
position
);
assert.equal(expectedItems.length, actualItems.length);
expectedItems.forEach((expectedItem, i) => {
const actualItem = actualItems[i];
assert.equal(
expectedItem.targetUri.fsPath,
actualItem.targetUri.fsPath
);
assert.equal(expectedItem.targetUri.fsPath, actualItem.targetUri.fsPath);
assert.ok(expectedItem.targetRange?.isEqual(actualItem.targetRange!));
assert.ok(
expectedItem.targetSelectionRange?.isEqual(
actualItem.targetSelectionRange!
)
);
assert.equal(
expectedItem.originSelectionRange,
actualItem.originSelectionRange
);
assert.ok(expectedItem.targetSelectionRange?.isEqual(actualItem.targetSelectionRange!));
assert.equal(expectedItem.originSelectionRange, actualItem.originSelectionRange);
});
}
Loading

0 comments on commit 0ae351d

Please sign in to comment.