mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-19 09:15:54 +00:00
Linting on save instead. Added a basic preprocess beginning, adding in the extension. Not complete
This commit is contained in:
parent
245471a5a2
commit
67e9c991a4
2 changed files with 29 additions and 4 deletions
|
@ -4,6 +4,8 @@ import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-lang
|
||||||
import { exec } from 'child_process'
|
import { exec } from 'child_process'
|
||||||
|
|
||||||
const reDiag = /(ERROR|WARNING): (?:\d):(\d+): '(?:.*)' : (.+)/
|
const reDiag = /(ERROR|WARNING): (?:\d):(\d+): '(?:.*)' : (.+)/
|
||||||
|
const reVersion = /#version [\d]{3}/
|
||||||
|
const include = '#extension GL_GOOGLE_include_directive : require'
|
||||||
|
|
||||||
const filters = [
|
const filters = [
|
||||||
/(No code generated)/,
|
/(No code generated)/,
|
||||||
|
@ -53,8 +55,23 @@ const replaceWord = (msg: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function preprocess(document: TextDocument) {
|
export function preprocess(document: TextDocument) {
|
||||||
|
const lines = document.getText().split('\n')
|
||||||
|
let inComment = false
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
const line = lines[i]
|
||||||
|
if (line.includes('/*')) inComment = true
|
||||||
|
if (line.includes('*/')) inComment = false
|
||||||
|
if (line.trim().startsWith('//')) break
|
||||||
|
if (!inComment && reVersion.test(line)) {
|
||||||
|
lines.splice(i + 1, 0, include)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (i === lines.length - 1) lines.splice(0, 0, include)
|
||||||
|
}
|
||||||
|
console.log(lines.join('\n'))
|
||||||
|
|
||||||
//const root = document.uri.replace(/^file:\/\//, '').replace(conf.minecraftPath, '').replace(path.basename(document.uri), '')
|
//const root = document.uri.replace(/^file:\/\//, '').replace(conf.minecraftPath, '').replace(path.basename(document.uri), '')
|
||||||
lint(document.getText(), document.uri)
|
lint(lines.join('\n'), document.uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
function lint(text: string, uri: string) {
|
function lint(text: string, uri: string) {
|
||||||
|
@ -65,7 +82,7 @@ function lint(text: string, uri: string) {
|
||||||
const [type, line, msg] = match.slice(1)
|
const [type, line, msg] = match.slice(1)
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
severity: type === 'ERROR' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning,
|
severity: type === 'ERROR' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning,
|
||||||
range: calcRange(parseInt(line), uri),
|
range: calcRange(parseInt(line) - 1, uri),
|
||||||
message: replaceWord(msg),
|
message: replaceWord(msg),
|
||||||
source: 'mc-glsl'
|
source: 'mc-glsl'
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,10 +22,18 @@ connection.onInitialize((params): vsclang.InitializeResult => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
documents.onDidChangeContent((change) => {
|
documents.onDidOpen((event) => {
|
||||||
|
preprocess(event.document)
|
||||||
|
})
|
||||||
|
|
||||||
|
documents.onDidSave((event) => {
|
||||||
|
preprocess(event.document)
|
||||||
|
})
|
||||||
|
|
||||||
|
/* documents.onDidChangeContent((change) => {
|
||||||
preprocess(change.document);
|
preprocess(change.document);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
connection.onDidChangeConfiguration((change) => {
|
connection.onDidChangeConfiguration((change) => {
|
||||||
const temp = change.settings.mcglsl as Config
|
const temp = change.settings.mcglsl as Config
|
||||||
conf = new Config(temp.minecraftPath, temp.glslangPath)
|
conf = new Config(temp.minecraftPath, temp.glslangPath)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue