From a65a6c1bb317c6c9fd3f0b5a1dae1e3a21a89e23 Mon Sep 17 00:00:00 2001 From: Noah Santschi-Cooney Date: Mon, 4 Jun 2018 20:25:57 +0100 Subject: [PATCH] Some basic completion provider. Need to go through all the options and tweak them --- .gitignore | 3 + .vscode/launch.json | 4 +- .vscode/settings.json | 3 +- client/tsconfig.json | 2 +- package.json | 4 +- server/package.json | 4 +- server/src/completionProvider.ts | 363 +++++++++++++++++++++++++++++++ server/src/server.ts | 39 +--- shaders.py | 18 ++ 9 files changed, 399 insertions(+), 41 deletions(-) create mode 100644 server/src/completionProvider.ts create mode 100644 shaders.py diff --git a/.gitignore b/.gitignore index a2c866e..00e9213 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ node_modules .vscode-test/ *.vsix +client/server +*.txt +*.out \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index e944143..783d6e8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "outFiles": [ "${workspaceRoot}/client/out/**/*.js" ], - "preLaunchTask": "compile" + "preLaunchTask": "compile:client" }, { "name": "Attach to Server", @@ -22,7 +22,7 @@ "sourceMaps": true, "outFiles": [ "${workspaceRoot}/client/server/**/*.js" - ], + ], "protocol": "legacy", "preLaunchTask": "watch:server" } diff --git a/.vscode/settings.json b/.vscode/settings.json index aeb132c..a05f7cf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,6 @@ }, "search.exclude": { "out": true // set this to false to include "out" folder in search results - } + }, + "python.pythonPath": "/usr/bin/python3" } \ No newline at end of file diff --git a/client/tsconfig.json b/client/tsconfig.json index 51ae0d6..3638ecf 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -10,7 +10,7 @@ "rootDir": "src", "strict": true, "noUnusedLocals": true, - "noImplicitReturns": true, + "noImplicitReturns": true }, "exclude": [ "node_modules", diff --git a/package.json b/package.json index 0808cdb..93b67d9 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,11 @@ }, "scripts": { "postinstall": "cd server && npm install && cd ../client && npm install && cd ..", - "compile": "tsc -p client/tsconfig.json && cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json", + "compile": "npm run compile:client && npm run compile:server", "run": "concurrently \"npm run watch:client\" \"npm run watch:server\"", "compile:client": "tsc -p client/tsconfig.json", - "watch:client": "tsc -w -p client/tsconfig.json", "compile:server": "cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json", + "watch:client": "tsc -w -p client/tsconfig.json", "watch:server": "cd server && npm run installServer && cd .. && tsc -w -p server/tsconfig.json", "lint": "cd server && npm run lint && cd ../client && npm run lint" }, diff --git a/server/package.json b/server/package.json index e96cd64..9c39132 100644 --- a/server/package.json +++ b/server/package.json @@ -22,7 +22,7 @@ "scripts": { "installServer": "installServerIntoExtension ../client ./package.json ./tsconfig.json", "compile": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -p .", - "watch": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -w -p .", - "lint": "tslint -c tslint.json 'src/**/*.ts'" + "watch": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -w -p .", + "lint": "tslint -c tslint.json 'src/**/*.ts'" } } diff --git a/server/src/completionProvider.ts b/server/src/completionProvider.ts new file mode 100644 index 0000000..5712352 --- /dev/null +++ b/server/src/completionProvider.ts @@ -0,0 +1,363 @@ +import { CompletionItem, CompletionItemKind } from 'vscode-languageserver' + +const value = CompletionItemKind.Value + +export const completions: CompletionItem[] = [ + { + label: 'heldItemId', + detail: ' held item ID (main hand)' + }, + { + label: 'heldBlockLightValue', + detail: ' held item light value (main hand)' + }, + { + label: 'heldItemId2', + detail: ' held item ID (off hand)' + }, + { + label: 'heldBlockLightValue2', + detail: ' held item light value (off hand)' + }, + { + label: 'fogMode', + detail: ' GL_LINEAR, GL_EXP or GL_EXP2' + }, + { + label: 'fogColor', + detail: ' r, g, b' + }, + { + label: 'skyColor', + detail: ' r, g, b' + }, + { + label: 'worldTime', + detail: ' = worldTicks % 24000' + }, + { + label: 'worldDay', + detail: ' = worldTicks / 24000' + }, + { + label: 'moonPhase', + detail: ' 0-7' + }, + { + label: 'frameCounter', + detail: ' Frame index (0 to 720719, then resets to 0)' + }, + { + label: 'frameTime', + detail: ' last frame time, seconds' + }, + { + label: 'frameTimeCounter', + detail: ' run time, seconds (resets to 0 after 3600s)' + }, + { + label: 'sunAngle', + detail: ' 0.0-1.0' + }, + { + label: 'shadowAngle', + detail: ' 0.0-1.0' + }, + { + label: 'rainStrength', + detail: ' 0.0-1.0' + }, + { + label: 'aspectRatio', + detail: ' viewWidth / viewHeight' + }, + { + label: 'viewWidth', + detail: ' viewWidth' + }, + { + label: 'viewHeight', + detail: ' viewHeight' + }, + { + label: 'near', + detail: ' near viewing plane distance' + }, + { + label: 'far', + detail: ' far viewing plane distance' + }, + { + label: 'sunPosition', + detail: ' sun position in eye space' + }, + { + label: 'moonPosition', + detail: ' moon position in eye space' + }, + { + label: 'shadowLightPosition', + detail: ' shadow light (sun or moon) position in eye space' + }, + { + label: 'upPosition', + detail: ' direction up' + }, + { + label: 'cameraPosition', + detail: ' camera position in world space' + }, + { + label: 'previousCameraPosition', + detail: ' last frame cameraPosition' + }, + { + label: 'gbufferModelView', + detail: ' modelview matrix after setting up the camera transformations' + }, + { + label: 'gbufferModelViewInverse', + detail: ' inverse gbufferModelView' + }, + { + label: 'gbufferPreviousModelView', + detail: ' last frame gbufferModelView' + }, + { + label: 'gbufferProjection', + detail: ' projection matrix when the gbuffers were generated' + }, + { + label: 'gbufferProjectionInverse', + detail: ' inverse gbufferProjection' + }, + { + label: 'gbufferPreviousProjection', + detail: ' last frame gbufferProjection' + }, + { + label: 'shadowProjection', + detail: ' projection matrix when the shadow map was generated' + }, + { + label: 'shadowProjectionInverse', + detail: ' inverse shadowProjection' + }, + { + label: 'shadowModelView', + detail: ' modelview matrix when the shadow map was generated' + }, + { + label: 'shadowModelViewInverse', + detail: ' inverse shadowModelView' + }, + { + label: 'wetness', + detail: ' rainStrength smoothed with wetnessHalfLife or drynessHalfLife' + }, + { + label: 'eyeAltitude', + detail: ' view entity Y position' + }, + { + label: 'eyeBrightness', + detail: ' x = block brightness, y = sky brightness, light 0-15 = brightness 0-240' + }, + { + label: 'eyeBrightnessSmooth', + detail: ' eyeBrightness smoothed with eyeBrightnessHalflife' + }, + { + label: 'terrainTextureSize', + detail: ' not used' + }, + { + label: 'terrainIconSize', + detail: ' not used' + }, + { + label: 'isEyeInWater', + detail: ' 1 = camera is in water, 2 = camera is in lava' + }, + { + label: 'nightVision', + detail: ' night vision (0.0-1.0)' + }, + { + label: 'blindness', + detail: ' blindness (0.0-1.0)' + }, + { + label: 'screenBrightness', + detail: ' screen brightness (0.0-1.0)' + }, + { + label: 'hideGUI', + detail: ' GUI is hidden' + }, + { + label: 'centerDepthSmooth', + detail: ' centerDepth smoothed with centerDepthSmoothHalflife' + }, + { + label: 'atlasSize', + detail: ' texture atlas size (only set when the atlas texture is bound)' + }, + { + label: 'entityColor', + detail: ' entity color multiplier (entity hurt, creeper flashing when exploding)' + }, + { + label: 'entityId', + detail: ' entity ID' + }, + { + label: 'blockEntityId', + detail: ' block entity ID (block ID for the tile entity)' + }, + { + label: 'blendFunc', + detail: ' blend function (srcRGB, dstRGB, srcAlpha, dstAlpha)' + }, + { + label: 'texture', + detail: '' + }, + { + label: 'lightmap', + detail: '' + }, + { + label: 'normals', + detail: '' + }, + { + label: 'specular', + detail: '' + }, + { + label: 'shadow', + detail: ' waterShadowEnabled ? 5 : 4' + }, + { + label: 'watershadow', + detail: '' + }, + { + label: 'shadowtex0', + detail: '' + }, + { + label: 'shadowtex1', + detail: '' + }, + { + label: 'depthtex0', + detail: '' + }, + { + label: 'gaux1', + detail: ' 7 ' + }, + { + label: 'gaux2', + detail: ' 8 ' + }, + { + label: 'gaux3', + detail: ' 9 ' + }, + { + label: 'gaux4', + detail: ' 10 ' + }, + { + label: 'depthtex1', + detail: '' + }, + { + label: 'shadowcolor', + detail: '' + }, + { + label: 'shadowcolor0', + detail: '' + }, + { + label: 'shadowcolor1', + detail: '' + }, + { + label: 'noisetex', + detail: '' + }, + { + label: 'tex', + detail: '' + }, + { + label: 'gcolor', + detail: '' + }, + { + label: 'gdepth', + detail: '' + }, + { + label: 'gnormal', + detail: '' + }, + { + label: 'composite', + detail: '' + }, + { + label: 'colortex0', + detail: '' + }, + { + label: 'colortex1', + detail: '' + }, + { + label: 'colortex2', + detail: '' + }, + { + label: 'colortex3', + detail: '' + }, + { + label: 'colortex4', + detail: '' + }, + { + label: 'colortex5', + detail: '' + }, + { + label: 'colortex6', + detail: '' + }, + { + label: 'colortex7', + detail: '' + }, + { + label: 'gdepthtex', + detail: '' + }, + { + label: 'depthtex2', + detail: '' + }, + { + label: 'depthtex3', + detail: ' depthBuffers = 4' + } +] + +for (let i = 1; i < completions.length + 1; i++) { + completions[i - 1].data = i + completions[i - 1].kind = value +} \ No newline at end of file diff --git a/server/src/server.ts b/server/src/server.ts index 9d1fbcc..795f1bf 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1,5 +1,6 @@ import * as vsclang from 'vscode-languageserver' import { Config } from './config' +import { completions } from './completionProvider'; const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process)); @@ -12,7 +13,7 @@ const conf = new Config('', '') connection.onInitialize((params): vsclang.InitializeResult => { return { capabilities: { - textDocumentSync: vsclang.TextDocumentSyncKind.Incremental, + textDocumentSync: documents.syncKind, completionProvider: { resolveProvider: true }, @@ -29,19 +30,7 @@ connection.onDidChangeConfiguration((change) => { documents.all().forEach(validateTextDocument); }); -connection.onDidChangeTextDocument((param) => { - console.log(param.contentChanges) -}) - -connection.onDidOpenTextDocument((param) => { - console.log(param) -}) - -connection.onDidCloseTextDocument((param) => { - console.log(param) -}) - -function validateTextDocument(textDocument: vsclang.TextDocument) { +function validateTextDocument(textDocument: vsclang.TextDocument): void { const diagnostics: vsclang.Diagnostic[] = []; const lines = textDocument.getText().split(/\r?\n/g); for (let i = 0; i < lines.length; i++) { @@ -54,7 +43,7 @@ function validateTextDocument(textDocument: vsclang.TextDocument) { start: { line: i, character: index }, end: { line: i, character: index + 10 } }, - message: `blah blah Todd Howard`, + message: `bananas`, source: 'mcglsl' }); } @@ -64,27 +53,11 @@ function validateTextDocument(textDocument: vsclang.TextDocument) { } connection.onCompletion((textDocumentPosition: vsclang.TextDocumentPositionParams): vsclang.CompletionItem[] => { - return [ - { - label: 'heldItemId', - kind: vsclang.CompletionItemKind.Variable, - data: 0, - },{ - label: 'hot', - kind: vsclang.CompletionItemKind.Property, - data: 1 - }]; + return completions }); connection.onCompletionResolve((item: vsclang.CompletionItem): vsclang.CompletionItem => { - if (item.data === 0) { - item.documentation = 'blyat man' - item.detail = 'Held item ID (main hand)' - } else if (item.data === 1) { - item.documentation = 'random' - item.detail = 'something' - } - return item + return completions[item.data - 1] }); connection.listen(); \ No newline at end of file diff --git a/shaders.py b/shaders.py new file mode 100644 index 0000000..dc42af8 --- /dev/null +++ b/shaders.py @@ -0,0 +1,18 @@ +with open('shaders.txt') as f: + items = {} + lines = filter(lambda s: s.startswith('uniform'), f.readlines()) + for line in lines: + err = False + try: + detail = int(' '.join(line.split()[3:])) + err = True + except: + pass + type = line.split()[1].rstrip('>').lstrip('<') + detail = ' '.join(line.split()[3:]) if not err else '' + label = line.split()[2].rstrip(';') + if label in items: + continue + items[label] = True + detail = ' ' + detail if not detail == '' else '' + print('{\n\tlabel: \'%s\',\n\tdetail: \'<%s>%s\'\n},' % (label, type, detail)) \ No newline at end of file