diff --git a/server/src/config.ts b/server/src/config.ts index 95e66fa..761a910 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -20,7 +20,7 @@ export let conf: Config = {shaderpacksPath: '', glslangPath: ''} export const onConfigChange = async (change) => { const temp = change.settings.mcglsl as Config - conf = {shaderpacksPath: temp['shaderpacksPath'], glslangPath: temp['glslangValidatorPath']} + conf = {shaderpacksPath: temp['shaderpacksPath'].replace(/\\/g, '/'), glslangPath: temp['glslangValidatorPath'].replace(/\\/g, '/')} if (existsSync(conf.glslangPath)) { documents.all().forEach(onEvent) diff --git a/server/src/linter.ts b/server/src/linter.ts index 963c79d..7eac203 100644 --- a/server/src/linter.ts +++ b/server/src/linter.ts @@ -4,12 +4,12 @@ import { execSync } from 'child_process' import * as path from 'path' import { readFileSync, existsSync } from 'fs' import { conf } from './config' -import { postError } from './utils' +import { postError, formatURI } from './utils' import { platform } from 'os' -const reDiag = /^(ERROR|WARNING): ([^?<>:*|"]+?):(\d+): (?:'.*?' : )?(.+)[\r\n|\n]/ +const reDiag = /^(ERROR|WARNING): ([^?<>*|"]+?):(\d+): (?:'.*?' : )?(.+)\r?/ const reVersion = /#version [\d]{3}/ -const reInclude = /^(?:\s)*?(?:#include) "((?:\/?[^?<>:*|"]+?)+?\.(?:[a-zA-Z]+?))"[\r\n|\n]/ +const reInclude = /^(?:\s)*?(?:#include) "((?:\/?[^?<>:*|"]+?)+?\.(?:[a-zA-Z]+?))"\r?/ const reIncludeExt = /#extension GL_GOOGLE_include_directive ?: ?require/ const include = '#extension GL_GOOGLE_include_directive : require' const win = platform() === 'win32' @@ -148,10 +148,10 @@ export function getIncludes(uri: string, lines: string[]) { if (match) { out.push({ - path: absPath(parStack[parStack.length - 1], match[1]), + path: formatURI(absPath(parStack[parStack.length - 1], match[1])), lineNum: count[count.length - 1], lineNumTopLevel: total, - parent: parStack[parStack.length - 1], + parent: formatURI(parStack[parStack.length - 1]), match }) } @@ -182,7 +182,7 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag // TODO deal with the fact that includes may not be the sole text on a line // add #line indicating we are entering a new include block - lines[inc.lineNumTopLevel] = `#line 0 "${inc.path}"` + lines[inc.lineNumTopLevel] = `#line 0 "${formatURI(inc.path)}"` // merge the lines of the file into the current document // TODO do we wanna use a DLL here? lines.splice(inc.lineNumTopLevel + 1, 0, ...dataLines) @@ -207,12 +207,11 @@ function lint(uri: string, lines: string[], includes: Map, d filterMatches(out).forEach((match) => { const [whole, type, file, line, msg] = match - let diag: Diagnostic = { severity: errorType(type), // had to do - 2 here instead of - 1, windows only perhaps? range: calcRange(parseInt(line) - (win ? 2 : 1), file.length - 1 ? file : uri), - message: replaceWord(msg), + message: replaceWords(msg), source: 'mc-glsl' } @@ -224,8 +223,8 @@ function lint(uri: string, lines: string[], includes: Map, d // TODO what if we dont know the top level parent? Feel like thats a non-issue given that we have uri diag = { severity: errorType(type), - range: calcRange(includes.get(nextFile).lineNum, includes.get(nextFile).parent), - message: includes.get(file).path.replace(conf.shaderpacksPath, '') + replaceWord(msg), + range: calcRange(includes.get(nextFile).lineNum - (win ? 1 : 0), includes.get(nextFile).parent), + message: includes.get(file).path.replace(conf.shaderpacksPath, '') + replaceWords(msg), source: 'mc-glsl' } @@ -236,11 +235,12 @@ function lint(uri: string, lines: string[], includes: Map, d }) daigsArray(diagnostics).forEach(d => { + if (win) d.uri = d.uri.replace('file://C:', 'file:///c%3A') connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag}) }) } -export const replaceWord = (msg: string) => Array.from(tokens.entries()).reduce((acc, [key, value]) => acc.replace(key, value), msg) +export const replaceWords = (msg: string) => Array.from(tokens.entries()).reduce((acc, [key, value]) => acc.replace(key, value), msg) const errorType = (error: string) => error === 'ERROR' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning @@ -268,10 +268,7 @@ function calcRange(lineNum: number, uri: string): Range { return Range.create(lineNum, startOfLine, lineNum, endOfLine) } -export const formatURI = (uri: string) => uri.replace(/^file:\/\//, '') - export function absPath(currFile: string, includeFile: string): string { - console.log(currFile) if (!currFile.startsWith(conf.shaderpacksPath) || conf.shaderpacksPath === '') { connection.window.showErrorMessage(`Shaderpacks path may not be correct. Current file is in '${currFile}' but the path is set to '${conf.shaderpacksPath}'`) return '' diff --git a/server/src/server.ts b/server/src/server.ts index aa67a69..22e0c2b 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1,13 +1,14 @@ import * as vsclang from 'vscode-languageserver' import * as vsclangproto from 'vscode-languageserver-protocol' import { completions } from './completionProvider' -import { preprocess, ext, formatURI } from './linter' +import { preprocess, ext } from './linter' import { extname } from 'path' export let connection: vsclang.IConnection connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process)) import { onConfigChange } from './config' +import { formatURI } from './utils' export const documents = new vsclang.TextDocuments() documents.listen(connection) @@ -37,6 +38,8 @@ documents.onDidClose((event) => connection.sendDiagnostics({uri: event.document. export function onEvent(document: vsclangproto.TextDocument) { if (!ext.has(extname(document.uri))) return try { + console.log(document.uri) + console.log(formatURI(document.uri)) preprocess(document.getText().split('\n'), formatURI(document.uri)) } catch (e) { connection.window.showErrorMessage(`[mc-glsl] ${e.message}`) diff --git a/server/src/utils.ts b/server/src/utils.ts index 6bc310f..57b8991 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -3,4 +3,6 @@ import { connection } from './server' export function postError(e: Error) { connection.window.showErrorMessage(e.message) console.log(e) -} \ No newline at end of file +} + +export const formatURI = (uri: string) => uri.replace(/^file:\/\//, '').replace(/^(?:\/)c%3A/, 'C:').replace(/\\/g, '/') \ No newline at end of file