mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-19 09:15:54 +00:00
Added postError function for short error notifications. Using existsSync to check if binary exists. Seperated onConfigChange into different functions. lineNum -2 for windows instead of -1 for linux, such a pain.
This commit is contained in:
parent
c8c7a29abb
commit
1cec184e04
4 changed files with 69 additions and 57 deletions
|
@ -1,10 +1,9 @@
|
|||
import { connection, documents, onEvent } from './server'
|
||||
import { exec, execSync } from 'child_process'
|
||||
import { extname } from 'path'
|
||||
import fetch from 'node-fetch'
|
||||
import { platform } from 'os'
|
||||
import { createWriteStream, chmodSync, createReadStream, unlinkSync } from 'fs'
|
||||
import { createWriteStream, chmodSync, createReadStream, unlinkSync, existsSync } from 'fs'
|
||||
import * as unzip from 'unzip'
|
||||
import { postError } from './utils'
|
||||
|
||||
const url = {
|
||||
'win32': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip',
|
||||
|
@ -17,18 +16,22 @@ export interface Config {
|
|||
readonly glslangPath: string
|
||||
}
|
||||
|
||||
export let conf: Partial<Config> = {}
|
||||
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']}
|
||||
try {
|
||||
execSync(conf.glslangPath)
|
||||
documents.all().forEach(document => onEvent)
|
||||
} catch (e) {
|
||||
if (e.status !== 1) {
|
||||
|
||||
if (existsSync(conf.glslangPath)) {
|
||||
documents.all().forEach(onEvent)
|
||||
} else {
|
||||
promptDownloadGlslang()
|
||||
}
|
||||
}
|
||||
|
||||
async function promptDownloadGlslang() {
|
||||
const chosen = await connection.window.showErrorMessage(
|
||||
`[mc-glsl] glslangValidator not found at: '${conf.glslangPath}' or returned non-0 code`,
|
||||
`[mc-glsl] glslangValidator not found at: '${conf.glslangPath}'.`,
|
||||
{title: 'Download'},
|
||||
{title: 'Cancel'}
|
||||
)
|
||||
|
@ -36,10 +39,14 @@ export const onConfigChange = async (change) => {
|
|||
if (!chosen || chosen.title !== 'Download') return
|
||||
|
||||
if (conf.shaderpacksPath === '') {
|
||||
connection.window.showErrorMessage('Please set mcglsl.shaderpacksPath')
|
||||
connection.window.showErrorMessage('Please set mcglsl.shaderpacksPath as this is where glslangValidator will be saved to.')
|
||||
return
|
||||
}
|
||||
|
||||
downloadGlslang()
|
||||
}
|
||||
|
||||
async function downloadGlslang() {
|
||||
const res = await fetch(url[platform()])
|
||||
|
||||
try {
|
||||
|
@ -49,7 +56,7 @@ export const onConfigChange = async (change) => {
|
|||
zip.on('finish', async () => {
|
||||
createReadStream(conf.shaderpacksPath + '/glslangValidator.zip')
|
||||
.pipe(unzip.Parse())
|
||||
.on('entry', (entry) => {
|
||||
.on('entry', entry => {
|
||||
if (entry.path === 'bin/glslangValidator') {
|
||||
entry.pipe(createWriteStream(conf.shaderpacksPath + '/glslangValidator'))
|
||||
return
|
||||
|
@ -64,8 +71,6 @@ export const onConfigChange = async (change) => {
|
|||
})
|
||||
})
|
||||
} catch (e) {
|
||||
connection.window.showErrorMessage(e.message)
|
||||
}
|
||||
}
|
||||
postError(e)
|
||||
}
|
||||
}
|
|
@ -1,23 +1,27 @@
|
|||
import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver'
|
||||
import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver'
|
||||
import { connection, documents } from './server'
|
||||
import { execSync } from 'child_process'
|
||||
import * as path from 'path'
|
||||
import { readFileSync, existsSync } from 'fs'
|
||||
import { conf } from './config'
|
||||
import { postError } from './utils'
|
||||
import { platform } from 'os'
|
||||
|
||||
const reDiag = /^(ERROR|WARNING): ([^?<>:*|"]+?):(\d+): (?:'.*?' : )?(.+)$/
|
||||
const reDiag = /^(ERROR|WARNING): ([^?<>:*|"]+?):(\d+): (?:'.*?' : )?(.+)[\r\n|\n]/
|
||||
const reVersion = /#version [\d]{3}/
|
||||
const reInclude = /^(?:\s)*?(?:#include) "((?:\/?[^?<>:*|"]+?)+?\.(?:[a-zA-Z]+?))"$/
|
||||
const reIncludeExt = /#extension GL_GOOGLE_include_directive ?: ?require/
|
||||
const include = '#extension GL_GOOGLE_include_directive : require'
|
||||
const win = platform() === 'win32'
|
||||
|
||||
const filters = [
|
||||
/stdin/,
|
||||
/(No code generated)/,
|
||||
/(compilation terminated)/,
|
||||
/Could not process include directive for header name:/
|
||||
]
|
||||
|
||||
const files = new Map<string, number>()
|
||||
const includeToParent = new Map<string, string[]>()
|
||||
|
||||
type IncludeObj = {
|
||||
lineNum: number,
|
||||
|
@ -98,7 +102,7 @@ export function preprocess(lines: string[], docURI: string) {
|
|||
try {
|
||||
lint(docURI, lines, includeMap, diagnostics)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
postError(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,6 +184,7 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
|
|||
// add #line indicating we are entering a new include block
|
||||
lines[inc.lineNumTopLevel] = `#line 0 "${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)
|
||||
// add the closing #line indicating we're re-entering a block a level up
|
||||
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum} "${inc.parent}"`)
|
||||
|
@ -205,7 +210,8 @@ function lint(uri: string, lines: string[], includes: Map<string, IncludeObj>, d
|
|||
|
||||
let diag: Diagnostic = {
|
||||
severity: errorType(type),
|
||||
range: calcRange(parseInt(line) - 1, file.length - 1 ? file : uri),
|
||||
// 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),
|
||||
source: 'mc-glsl'
|
||||
}
|
||||
|
|
|
@ -2,17 +2,12 @@ import * as vsclang from 'vscode-languageserver'
|
|||
import * as vsclangproto from 'vscode-languageserver-protocol'
|
||||
import { completions } from './completionProvider'
|
||||
import { preprocess, ext, formatURI } from './linter'
|
||||
import { exec, execSync } from 'child_process'
|
||||
import { extname } from 'path'
|
||||
import fetch from 'node-fetch'
|
||||
import { platform } from 'os'
|
||||
import { createWriteStream, chmodSync, createReadStream, unlinkSync } from 'fs'
|
||||
import * as unzip from 'unzip'
|
||||
|
||||
export let connection: vsclang.IConnection
|
||||
connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process))
|
||||
|
||||
import { Config, onConfigChange } from './config'
|
||||
import { onConfigChange } from './config'
|
||||
|
||||
export const documents = new vsclang.TextDocuments()
|
||||
documents.listen(connection)
|
||||
|
|
6
server/src/utils.ts
Normal file
6
server/src/utils.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { connection } from './server'
|
||||
|
||||
export function postError(e: Error) {
|
||||
connection.window.showErrorMessage(e.message)
|
||||
console.log(e)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue