mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-02 08:02:58 +00:00
And thus stage 1 of includes is complete. One-depth includes work!
This commit is contained in:
parent
481addd033
commit
17d84bad6b
3 changed files with 33 additions and 41 deletions
|
@ -3,7 +3,7 @@ import './global'
|
|||
import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver'
|
||||
import { exec } from 'child_process'
|
||||
import * as path from 'path'
|
||||
import { readFileSync } from 'fs';
|
||||
import { readFileSync } from 'fs'
|
||||
|
||||
const reDiag = /^(ERROR|WARNING): ([^?<>:*|"]+?):(\d+): (?:'.*?' : )?(.+)$/
|
||||
const reVersion = /#version [\d]{3}/
|
||||
|
@ -18,7 +18,7 @@ const filters = [
|
|||
|
||||
const files: {[uri: string]: number} = {}
|
||||
|
||||
const ext = {
|
||||
export const ext = {
|
||||
'.fsh': 'frag',
|
||||
'.gsh': 'geom',
|
||||
'.vsh': 'vert',
|
||||
|
@ -66,23 +66,26 @@ export function preprocess(document: TextDocument, topLevel: boolean, incStack:
|
|||
lines.splice(i + 1, 0, include)
|
||||
break
|
||||
}
|
||||
if (i === lines.length - 1) lines.splice(0, 0, include)
|
||||
if (i === lines.length - 1) {
|
||||
lines.splice(0, 0, include)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const includes = getIncludes(lines)
|
||||
let addedLines = 0
|
||||
if (includes.length > 0) {
|
||||
includes.forEach((inc) => {
|
||||
includes.forEach((inc, i) => {
|
||||
const incPath = absPath(docURI, inc.match[1])
|
||||
const data = readFileSync(incPath)
|
||||
lines[inc.lineNum] = `#line 0 "${incPath}"`
|
||||
lines.splice(inc.lineNum + 1, 0, `#line ${inc.lineNum} "${docURI}"`)
|
||||
const dataLines = data.toString().split('\n')
|
||||
lines.splice(inc.lineNum + 1, 0, ...dataLines)
|
||||
//console.log(lines.join('\n'))
|
||||
const dataLines = readFileSync(incPath).toString().split('\n')
|
||||
lines[inc.lineNum + addedLines + i] = `#line 0 "${incPath}"`
|
||||
lines.splice(inc.lineNum + 1 + addedLines + i, 0, ...dataLines)
|
||||
addedLines += dataLines.length
|
||||
lines.splice(inc.lineNum + 1 + addedLines + i, 0, `#line ${inc.lineNum} "${docURI}"`)
|
||||
})
|
||||
}
|
||||
|
||||
console.log(lines.join('\n'))
|
||||
lint(docURI, lines.join('\n'), includes)
|
||||
}
|
||||
|
||||
|
@ -126,9 +129,7 @@ function lint(uri: string, text: string, includes: {lineNum: number, match: RegE
|
|||
}
|
||||
diagnostics[file].push(diag)
|
||||
})
|
||||
console.log(JSON.stringify(daigsArray(diagnostics), null, 2))
|
||||
daigsArray(diagnostics).forEach((d) => {
|
||||
console.log(d.uri, d.diag.length)
|
||||
connection.sendDiagnostics({uri: 'file://' + d.uri, diagnostics: d.diag})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import * as vsclang from 'vscode-languageserver'
|
||||
import { TextDocumentChangeEvent } from 'vscode-languageserver-protocol';
|
||||
import { TextDocumentChangeEvent } from 'vscode-languageserver-protocol'
|
||||
import { Config } from './config'
|
||||
import { completions } from './completionProvider';
|
||||
import { preprocess } from './linter';
|
||||
import { exec } from 'child_process';
|
||||
import { completions } from './completionProvider'
|
||||
import { preprocess, ext } from './linter'
|
||||
import { exec } from 'child_process'
|
||||
import { extname } from 'path'
|
||||
|
||||
export const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process));
|
||||
export const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process))
|
||||
|
||||
export const documents = new vsclang.TextDocuments();
|
||||
documents.listen(connection);
|
||||
export const documents = new vsclang.TextDocuments()
|
||||
documents.listen(connection)
|
||||
|
||||
export let conf = new Config('', '')
|
||||
|
||||
|
@ -20,24 +21,18 @@ connection.onInitialize((params): vsclang.InitializeResult => {
|
|||
resolveProvider: true
|
||||
},
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
connection.onExit(() => {
|
||||
|
||||
})
|
||||
|
||||
documents.onDidOpen((event) => {
|
||||
//onEvent(event)
|
||||
})
|
||||
documents.onDidOpen(onEvent)
|
||||
|
||||
documents.onDidSave((event) => {
|
||||
onEvent(event)
|
||||
})
|
||||
documents.onDidSave(onEvent)
|
||||
|
||||
documents.onDidChangeContent((event) => {
|
||||
//onEvent(event)
|
||||
})
|
||||
//documents.onDidChangeContent(onEvent)
|
||||
|
||||
function onEvent(event: TextDocumentChangeEvent) {
|
||||
preprocess(event.document, true, [event.document.uri.replace(/^file:\/\//, '')])
|
||||
|
@ -51,16 +46,12 @@ connection.onDidChangeConfiguration((change) => {
|
|||
connection.window.showErrorMessage(`[mc-glsl] glslangValidator not found at: ${conf.glslangPath}`)
|
||||
return
|
||||
}
|
||||
documents.all().forEach((document) => preprocess(document, true, [document.uri.replace(/^file:\/\//, '')]));
|
||||
documents.all().forEach((document) => preprocess(document, true, [document.uri.replace(/^file:\/\//, '')]))
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
connection.onCompletion((textDocumentPosition: vsclang.TextDocumentPositionParams): vsclang.CompletionItem[] => {
|
||||
return completions
|
||||
});
|
||||
connection.onCompletion((textDocumentPosition: vsclang.TextDocumentPositionParams) => completions)
|
||||
|
||||
connection.onCompletionResolve((item: vsclang.CompletionItem): vsclang.CompletionItem => {
|
||||
return completions[item.data - 1]
|
||||
});
|
||||
connection.onCompletionResolve((item: vsclang.CompletionItem): vsclang.CompletionItem => completions[item.data - 1])
|
||||
|
||||
connection.listen();
|
||||
connection.listen()
|
Loading…
Add table
Add a link
Reference in a new issue