mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-19 17:26:13 +00:00
Added logLevel setting
Added quick linux version of fromFileURI
This commit is contained in:
parent
b8acc6837e
commit
d7d8f9de96
6 changed files with 90 additions and 95 deletions
|
@ -55,6 +55,12 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
"description": "Absolute path to your Minecraft's shaderpacks folder."
|
"description": "Absolute path to your Minecraft's shaderpacks folder."
|
||||||
|
},
|
||||||
|
"mcglsl.logLevel": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "info",
|
||||||
|
"description": "Verbosity of output logging.",
|
||||||
|
"enum": ["debug", "info", "warn", "error"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,7 +357,7 @@ export const completions: CompletionItem[] = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
for (let i = 1; i < completions.length + 1; i++) {
|
for (let i = 0; i < completions.length; i++) {
|
||||||
completions[i - 1].data = i
|
completions[i].data = i
|
||||||
completions[i - 1].kind = value
|
completions[i].kind = value
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
import { dirname } from 'path'
|
import { dirname } from 'path'
|
||||||
import { DidChangeConfigurationParams } from 'vscode-languageserver'
|
import { DidChangeConfigurationParams } from 'vscode-languageserver'
|
||||||
import { GLSLangProvider } from './glslangValidator'
|
import { GLSLangProvider } from './glslangValidator'
|
||||||
import { serverLog as log } from './logging'
|
import { configLog as log, loggers } from './logging'
|
||||||
import { connection } from './server'
|
import { connection } from './server'
|
||||||
|
|
||||||
const url = {
|
const url = {
|
||||||
|
@ -12,25 +12,22 @@ const url = {
|
||||||
|
|
||||||
export let glslangReady = false
|
export let glslangReady = false
|
||||||
|
|
||||||
|
// Maps the JSON settings from VSCode to an object
|
||||||
|
interface Config {
|
||||||
|
shaderpacksPath: string
|
||||||
|
glslangValidatorPath: string
|
||||||
|
logLevel: 'error' | 'warn' | 'info' | 'debug'
|
||||||
|
}
|
||||||
|
|
||||||
export class ConfigProvider {
|
export class ConfigProvider {
|
||||||
private _config: Config
|
private _config: Config
|
||||||
private _onChange: (settings: Config) => void
|
|
||||||
private _glslang: GLSLangProvider
|
private _glslang: GLSLangProvider
|
||||||
|
|
||||||
public constructor(func?: (confProv: ConfigProvider, settings: Config) => void) {
|
public constructor() {
|
||||||
this._config = {
|
this._config = {
|
||||||
shaderpacksPath: '',
|
shaderpacksPath: '',
|
||||||
glslangValidatorPath: ''
|
glslangValidatorPath: '',
|
||||||
}
|
logLevel: 'info'
|
||||||
|
|
||||||
if (!func) {
|
|
||||||
this._onChange = (settings: Config) => {
|
|
||||||
onConfigChange(this, settings)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this._onChange = (settings: Config) => {
|
|
||||||
func(this, settings)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,14 +39,8 @@ export class ConfigProvider {
|
||||||
return this._config
|
return this._config
|
||||||
}
|
}
|
||||||
|
|
||||||
public set onChange(func: (confProv: ConfigProvider, settings: Config) => void) {
|
|
||||||
this._onChange = (settings: Config) => {
|
|
||||||
func(this, settings)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public onConfigChange = (change: DidChangeConfigurationParams) => {
|
public onConfigChange = (change: DidChangeConfigurationParams) => {
|
||||||
this._onChange(change.settings.mcglsl as Config)
|
onConfigChange(this, change.settings.mcglsl as Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
public set glslang(glslang: GLSLangProvider) {
|
public set glslang(glslang: GLSLangProvider) {
|
||||||
|
@ -61,39 +52,52 @@ export class ConfigProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Config {
|
|
||||||
shaderpacksPath: string
|
|
||||||
glslangValidatorPath: string
|
|
||||||
}
|
|
||||||
|
|
||||||
let supress = false
|
let supress = false
|
||||||
|
|
||||||
async function onConfigChange(confProv: ConfigProvider, old: Config) {
|
async function onConfigChange(confProv: ConfigProvider, current: Config) {
|
||||||
if (!confProv.config == undefined &&
|
if (!confProv.config == undefined &&
|
||||||
old.shaderpacksPath === confProv.config.shaderpacksPath &&
|
current.shaderpacksPath === confProv.config.shaderpacksPath &&
|
||||||
old.glslangValidatorPath === confProv.config.glslangValidatorPath) return
|
current.glslangValidatorPath === confProv.config.glslangValidatorPath &&
|
||||||
|
current.logLevel === confProv.config.logLevel) return
|
||||||
|
|
||||||
confProv.config = {shaderpacksPath: old['shaderpacksPath'], glslangValidatorPath: old['glslangValidatorPath']}
|
log.debug('new config: ' + JSON.stringify(current, Object.keys(current).sort()))
|
||||||
log.debug('new config: ' + JSON.stringify(old))
|
log.debug('old config: ' + JSON.stringify(confProv.config || {}, Object.keys(confProv.config).sort()))
|
||||||
log.debug('old config: ' + JSON.stringify(confProv.config))
|
confProv.config = {
|
||||||
|
shaderpacksPath: current['shaderpacksPath'],
|
||||||
|
glslangValidatorPath: current['glslangValidatorPath'],
|
||||||
|
logLevel: current['logLevel'],
|
||||||
|
}
|
||||||
|
|
||||||
if (confProv.config.shaderpacksPath === '' || confProv.config.shaderpacksPath.replace(dirname(confProv.config.shaderpacksPath), '') !== '/shaderpacks') {
|
// handle config.shaderpacksPath
|
||||||
if (supress) return
|
{
|
||||||
|
if (confProv.config.shaderpacksPath === '' || confProv.config.shaderpacksPath.replace(dirname(confProv.config.shaderpacksPath), '') !== '/shaderpacks') {
|
||||||
|
if (supress) return
|
||||||
|
|
||||||
log.error(`shaderpack path '${confProv.config.shaderpacksPath.replace(dirname(confProv.config.shaderpacksPath), '')}' not set or doesn't end in 'shaderpacks'`)
|
log.error(`shaderpack path '${confProv.config.shaderpacksPath.replace(dirname(confProv.config.shaderpacksPath), '')}' not set or doesn't end in 'shaderpacks'`)
|
||||||
supress = true
|
supress = true
|
||||||
|
|
||||||
const clicked = await connection.window.showErrorMessage(
|
const clicked = await connection.window.showErrorMessage(
|
||||||
'mcglsl.shaderpacksPath is not set or doesn\'t end in \'shaderpacks\'. Please set it in your settings.',
|
'mcglsl.shaderpacksPath is not set or doesn\'t end in \'shaderpacks\'. Please set it in your settings.',
|
||||||
{title: 'Supress'}
|
{title: 'Supress'}
|
||||||
)
|
)
|
||||||
supress = (clicked && clicked.title === 'Supress') ? true : false
|
supress = (clicked && clicked.title === 'Supress') ? true : false
|
||||||
return
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!confProv.glslang.testExecutable()) {
|
// handle config.logLevel
|
||||||
await confProv.glslang.promptDownload()
|
{
|
||||||
} else {
|
for(let logger of loggers) {
|
||||||
glslangReady = true
|
logger.level = current.logLevel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle config.glslang
|
||||||
|
{
|
||||||
|
if (!confProv.glslang.testExecutable()) {
|
||||||
|
await confProv.glslang.promptDownload()
|
||||||
|
} else {
|
||||||
|
glslangReady = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ export class GLSLangProvider {
|
||||||
|
|
||||||
const response = await fetch(url[platform()])
|
const response = await fetch(url[platform()])
|
||||||
log.warn('glslangValidator download response status: ' + response.status )
|
log.warn('glslangValidator download response status: ' + response.status )
|
||||||
|
|
||||||
const zip = new unzip(await response.buffer())
|
const zip = new unzip(await response.buffer())
|
||||||
|
|
||||||
const bin = zip.readFile('bin' + glslangBin)
|
const bin = zip.readFile('bin' + glslangBin)
|
||||||
|
@ -55,9 +56,7 @@ export class GLSLangProvider {
|
||||||
writeFileSync(glslangPath, bin, {encoding: null, mode: 0o755})
|
writeFileSync(glslangPath, bin, {encoding: null, mode: 0o755})
|
||||||
|
|
||||||
if (!this.testExecutable()) {
|
if (!this.testExecutable()) {
|
||||||
connection.window.showErrorMessage(
|
connection.window.showErrorMessage('Unexpected error occurred. Please try again')
|
||||||
'Unexpected error occurred. Please try again'
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +67,7 @@ export class GLSLangProvider {
|
||||||
connection.sendNotification('update-config', glslangPath)
|
connection.sendNotification('update-config', glslangPath)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error(`failed downloading glslangValidator ${e}`)
|
log.error(`failed downloading glslangValidator ${e}`)
|
||||||
connection.window.showErrorMessage(
|
connection.window.showErrorMessage(`Failed to install glslangValidator: ${e}`)
|
||||||
`Failed to install glslangValidator: ${e}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +81,7 @@ export class GLSLangProvider {
|
||||||
stdout = (e.stdout.toString() as string)
|
stdout = (e.stdout.toString() as string)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.warn('glslangValidator first line stdout: "' + stdout.split('\n')[0] + '"')
|
log.debug('glslangValidator first line stdout: "' + stdout.split('\n')[0] + '"')
|
||||||
const success = stdout.startsWith('Usage')
|
const success = stdout.startsWith('Usage')
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|
|
@ -1,43 +1,31 @@
|
||||||
import { Logger } from 'ts-log-debug'
|
import { Logger } from 'ts-log-debug'
|
||||||
|
|
||||||
|
const defaultOpts = {
|
||||||
|
type: 'stdout',
|
||||||
|
layout: {type: 'basic'},
|
||||||
|
levels: ['debug', 'info', 'warn', 'error']
|
||||||
|
}
|
||||||
|
|
||||||
export const glslProviderLog = new Logger('glslangProvider')
|
export const glslProviderLog = new Logger('glslangProvider')
|
||||||
glslProviderLog.appenders.set('std-log', {
|
glslProviderLog.appenders.set('std-log', defaultOpts)
|
||||||
type: 'stdout',
|
|
||||||
layout: {type: 'basic'},
|
|
||||||
levels: ['info', 'warn', 'error']
|
|
||||||
})
|
|
||||||
|
|
||||||
export const linterLog = new Logger('glslangProvider')
|
export const linterLog = new Logger('linter')
|
||||||
linterLog.appenders.set('std-log', {
|
linterLog.appenders.set('std-log', defaultOpts)
|
||||||
type: 'stdout',
|
|
||||||
layout: {type: 'basic'},
|
|
||||||
levels: ['info', 'warn', 'error']
|
|
||||||
})
|
|
||||||
|
|
||||||
export const completionLog = new Logger('glslangProvider')
|
export const completionLog = new Logger('completion')
|
||||||
completionLog.appenders.set('std-log', {
|
completionLog.appenders.set('std-log', defaultOpts)
|
||||||
type: 'stdout',
|
|
||||||
layout: {type: 'basic'},
|
|
||||||
levels: ['info', 'warn', 'error']
|
|
||||||
})
|
|
||||||
|
|
||||||
export const serverLog = new Logger('glslangProvider')
|
export const serverLog = new Logger('server')
|
||||||
serverLog.appenders.set('std-log', {
|
serverLog.appenders.set('std-log', defaultOpts)
|
||||||
type: 'stdout',
|
|
||||||
layout: {type: 'basic'},
|
|
||||||
levels: ['info', 'warn', 'error']
|
|
||||||
})
|
|
||||||
|
|
||||||
export const linkLog = new Logger('glslangProvider')
|
export const linkLog = new Logger('links')
|
||||||
linkLog.appenders.set('std-log', {
|
linkLog.appenders.set('std-log', defaultOpts)
|
||||||
type: 'stdout',
|
|
||||||
layout: {type: 'basic'},
|
|
||||||
levels: ['info', 'warn', 'error']
|
|
||||||
})
|
|
||||||
|
|
||||||
export const uriLog = new Logger('glslangProvider')
|
export const uriLog = new Logger('uri')
|
||||||
uriLog.appenders.set('std-log', {
|
uriLog.appenders.set('std-log', defaultOpts)
|
||||||
type: 'stdout',
|
|
||||||
layout: {type: 'basic'},
|
// not added to loggers as this should always log changes
|
||||||
levels: ['info', 'warn', 'error']
|
export const configLog = new Logger('config')
|
||||||
})
|
configLog.appenders.set('std-log', defaultOpts)
|
||||||
|
|
||||||
|
export const loggers = [glslProviderLog, linterLog, completionLog, serverLog, linkLog, uriLog]
|
|
@ -13,8 +13,8 @@ export class URI {
|
||||||
log.debug(`already normalized ${uri}`)
|
log.debug(`already normalized ${uri}`)
|
||||||
return uri
|
return uri
|
||||||
}
|
}
|
||||||
|
// TODO windows
|
||||||
return ''
|
return uri.replace(/^file:\/\//, '').replace(/\\/, '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
public static toFileURI(uri: string): string {
|
public static toFileURI(uri: string): string {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue