mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-19 17:26:13 +00:00
Added download prompt to download glslangValdiator
This commit is contained in:
parent
db321c8566
commit
c5fc9ffedd
7 changed files with 342 additions and 32 deletions
|
@ -1,9 +1,71 @@
|
|||
export class Config {
|
||||
public readonly shaderpacksPath: string
|
||||
public readonly glslangPath: string
|
||||
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 * as unzip from 'unzip'
|
||||
|
||||
constructor(shaderpacksPath: string, glslangPath: string) {
|
||||
this.shaderpacksPath = shaderpacksPath
|
||||
this.glslangPath = glslangPath || 'glslangValidator'
|
||||
const url = {
|
||||
'win32': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip',
|
||||
'linux': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip',
|
||||
'darwin': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-osx-Release.zip'
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
readonly shaderpacksPath: string
|
||||
readonly glslangPath: string
|
||||
}
|
||||
|
||||
export let conf: Partial<Config> = {}
|
||||
|
||||
connection.onDidChangeConfiguration(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) {
|
||||
const chosen = await connection.window.showErrorMessage(
|
||||
`[mc-glsl] glslangValidator not found at: '${conf.glslangPath}' or returned non-0 code`,
|
||||
{title: 'Download'},
|
||||
{title: 'Cancel'}
|
||||
)
|
||||
|
||||
if (!chosen || chosen.title !== 'Download') return
|
||||
|
||||
if (conf.shaderpacksPath === '') {
|
||||
connection.window.showErrorMessage('Please set mcglsl.shaderpacksPath')
|
||||
return
|
||||
}
|
||||
|
||||
const res = await fetch(url[platform()])
|
||||
|
||||
try {
|
||||
const zip = createWriteStream(conf.shaderpacksPath + '/glslangValidator.zip')
|
||||
res.body.pipe(zip)
|
||||
|
||||
zip.on('finish', async () => {
|
||||
createReadStream(conf.shaderpacksPath + '/glslangValidator.zip')
|
||||
.pipe(unzip.Parse())
|
||||
.on('entry', (entry) => {
|
||||
if (entry.path === 'bin/glslangValidator') {
|
||||
entry.pipe(createWriteStream(conf.shaderpacksPath + '/glslangValidator'))
|
||||
return
|
||||
}
|
||||
entry.autodrain()
|
||||
})
|
||||
.on('close', () => {
|
||||
chmodSync(conf.shaderpacksPath + '/glslangValidator', 0o775)
|
||||
unlinkSync(conf.shaderpacksPath + '/glslangValidator.zip')
|
||||
connection.sendNotification('update-config', conf.shaderpacksPath + '/glslangValidator')
|
||||
connection.window.showInformationMessage('glslangValidator has been downloaded to ' + conf.shaderpacksPath + '/glslangValidator')
|
||||
})
|
||||
})
|
||||
} catch (e) {
|
||||
connection.window.showErrorMessage(e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
|
@ -1,8 +1,9 @@
|
|||
import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver'
|
||||
import { conf, connection, documents } from './server'
|
||||
import { connection, documents } from './server'
|
||||
import { execSync } from 'child_process'
|
||||
import * as path from 'path'
|
||||
import { readFileSync } from 'fs'
|
||||
import { conf } from './config'
|
||||
|
||||
const reDiag = /^(ERROR|WARNING): ([^?<>:*|"]+?):(\d+): (?:'.*?' : )?(.+)$/
|
||||
const reVersion = /#version [\d]{3}/
|
||||
|
@ -102,6 +103,7 @@ function processIncludes(lines: string[], incStack: string[]) {
|
|||
|
||||
function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[]) {
|
||||
const incPath = absPath(inc.parent, inc.match[1])
|
||||
console.log(incPath)
|
||||
if (!incPath) return false
|
||||
const dataLines = readFileSync(incPath).toString().split('\n')
|
||||
incStack.push(incPath)
|
||||
|
|
|
@ -5,14 +5,16 @@ 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 const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process))
|
||||
|
||||
export const documents = new vsclang.TextDocuments()
|
||||
documents.listen(connection)
|
||||
|
||||
export let conf = new Config('', '')
|
||||
|
||||
connection.onInitialize((params): vsclang.InitializeResult => {
|
||||
return {
|
||||
capabilities: {
|
||||
|
@ -32,7 +34,7 @@ documents.onDidSave((event) => onEvent(event.document))
|
|||
|
||||
//documents.onDidChangeContent(onEvent)
|
||||
|
||||
function onEvent(document: vsclangproto.TextDocument) {
|
||||
export function onEvent(document: vsclangproto.TextDocument) {
|
||||
if (!ext.has(extname(document.uri))) return
|
||||
try {
|
||||
preprocess(document.getText().split('\n'), formatURI(document.uri))
|
||||
|
@ -41,24 +43,6 @@ function onEvent(document: vsclangproto.TextDocument) {
|
|||
}
|
||||
}
|
||||
|
||||
connection.onDidChangeConfiguration(async (change) => {
|
||||
const temp = change.settings.mcglsl as Config
|
||||
conf = new Config(temp['shaderpacksPath'], temp['glslangValidatorPath'])
|
||||
try {
|
||||
execSync(conf.glslangPath)
|
||||
documents.all().forEach(document => onEvent)
|
||||
} catch (e) {
|
||||
if (e.status !== 1) {
|
||||
const chosen = await connection.window.showErrorMessage(
|
||||
`[mc-glsl] glslangValidator not found at: '${conf.glslangPath}' or returned non-0 code`,
|
||||
{title: 'Download'},
|
||||
{title: 'Cancel'}
|
||||
)
|
||||
console.log(chosen.title)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
connection.onCompletion((textDocumentPosition: vsclang.TextDocumentPositionParams) => completions)
|
||||
|
||||
connection.onCompletionResolve((item: vsclang.CompletionItem): vsclang.CompletionItem => completions[item.data - 1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue