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",
|
||||
"default": "",
|
||||
"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++) {
|
||||
completions[i - 1].data = i
|
||||
completions[i - 1].kind = value
|
||||
for (let i = 0; i < completions.length; i++) {
|
||||
completions[i].data = i
|
||||
completions[i].kind = value
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import { dirname } from 'path'
|
||||
import { DidChangeConfigurationParams } from 'vscode-languageserver'
|
||||
import { GLSLangProvider } from './glslangValidator'
|
||||
import { serverLog as log } from './logging'
|
||||
import { configLog as log, loggers } from './logging'
|
||||
import { connection } from './server'
|
||||
|
||||
const url = {
|
||||
|
@ -12,25 +12,22 @@ const url = {
|
|||
|
||||
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 {
|
||||
private _config: Config
|
||||
private _onChange: (settings: Config) => void
|
||||
private _glslang: GLSLangProvider
|
||||
|
||||
public constructor(func?: (confProv: ConfigProvider, settings: Config) => void) {
|
||||
public constructor() {
|
||||
this._config = {
|
||||
shaderpacksPath: '',
|
||||
glslangValidatorPath: ''
|
||||
}
|
||||
|
||||
if (!func) {
|
||||
this._onChange = (settings: Config) => {
|
||||
onConfigChange(this, settings)
|
||||
}
|
||||
} else {
|
||||
this._onChange = (settings: Config) => {
|
||||
func(this, settings)
|
||||
}
|
||||
glslangValidatorPath: '',
|
||||
logLevel: 'info'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,14 +39,8 @@ export class ConfigProvider {
|
|||
return this._config
|
||||
}
|
||||
|
||||
public set onChange(func: (confProv: ConfigProvider, settings: Config) => void) {
|
||||
this._onChange = (settings: Config) => {
|
||||
func(this, settings)
|
||||
}
|
||||
}
|
||||
|
||||
public onConfigChange = (change: DidChangeConfigurationParams) => {
|
||||
this._onChange(change.settings.mcglsl as Config)
|
||||
onConfigChange(this, change.settings.mcglsl as Config)
|
||||
}
|
||||
|
||||
public set glslang(glslang: GLSLangProvider) {
|
||||
|
@ -61,22 +52,24 @@ export class ConfigProvider {
|
|||
}
|
||||
}
|
||||
|
||||
interface Config {
|
||||
shaderpacksPath: string
|
||||
glslangValidatorPath: string
|
||||
}
|
||||
|
||||
let supress = false
|
||||
|
||||
async function onConfigChange(confProv: ConfigProvider, old: Config) {
|
||||
async function onConfigChange(confProv: ConfigProvider, current: Config) {
|
||||
if (!confProv.config == undefined &&
|
||||
old.shaderpacksPath === confProv.config.shaderpacksPath &&
|
||||
old.glslangValidatorPath === confProv.config.glslangValidatorPath) return
|
||||
current.shaderpacksPath === confProv.config.shaderpacksPath &&
|
||||
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(old))
|
||||
log.debug('old config: ' + JSON.stringify(confProv.config))
|
||||
log.debug('new config: ' + JSON.stringify(current, Object.keys(current).sort()))
|
||||
log.debug('old config: ' + JSON.stringify(confProv.config || {}, Object.keys(confProv.config).sort()))
|
||||
confProv.config = {
|
||||
shaderpacksPath: current['shaderpacksPath'],
|
||||
glslangValidatorPath: current['glslangValidatorPath'],
|
||||
logLevel: current['logLevel'],
|
||||
}
|
||||
|
||||
// handle config.shaderpacksPath
|
||||
{
|
||||
if (confProv.config.shaderpacksPath === '' || confProv.config.shaderpacksPath.replace(dirname(confProv.config.shaderpacksPath), '') !== '/shaderpacks') {
|
||||
if (supress) return
|
||||
|
||||
|
@ -90,10 +83,21 @@ async function onConfigChange(confProv: ConfigProvider, old: Config) {
|
|||
supress = (clicked && clicked.title === 'Supress') ? true : false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// handle config.logLevel
|
||||
{
|
||||
for(let logger of loggers) {
|
||||
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()])
|
||||
log.warn('glslangValidator download response status: ' + response.status )
|
||||
|
||||
const zip = new unzip(await response.buffer())
|
||||
|
||||
const bin = zip.readFile('bin' + glslangBin)
|
||||
|
@ -55,9 +56,7 @@ export class GLSLangProvider {
|
|||
writeFileSync(glslangPath, bin, {encoding: null, mode: 0o755})
|
||||
|
||||
if (!this.testExecutable()) {
|
||||
connection.window.showErrorMessage(
|
||||
'Unexpected error occurred. Please try again'
|
||||
)
|
||||
connection.window.showErrorMessage('Unexpected error occurred. Please try again')
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -68,9 +67,7 @@ export class GLSLangProvider {
|
|||
connection.sendNotification('update-config', glslangPath)
|
||||
} catch (e) {
|
||||
log.error(`failed downloading glslangValidator ${e}`)
|
||||
connection.window.showErrorMessage(
|
||||
`Failed to install glslangValidator: ${e}`
|
||||
)
|
||||
connection.window.showErrorMessage(`Failed to install glslangValidator: ${e}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +81,7 @@ export class GLSLangProvider {
|
|||
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')
|
||||
|
||||
if (success) {
|
||||
|
|
|
@ -1,43 +1,31 @@
|
|||
import { Logger } from 'ts-log-debug'
|
||||
|
||||
const defaultOpts = {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['debug', 'info', 'warn', 'error']
|
||||
}
|
||||
|
||||
export const glslProviderLog = new Logger('glslangProvider')
|
||||
glslProviderLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
glslProviderLog.appenders.set('std-log', defaultOpts)
|
||||
|
||||
export const linterLog = new Logger('glslangProvider')
|
||||
linterLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
export const linterLog = new Logger('linter')
|
||||
linterLog.appenders.set('std-log', defaultOpts)
|
||||
|
||||
export const completionLog = new Logger('glslangProvider')
|
||||
completionLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
export const completionLog = new Logger('completion')
|
||||
completionLog.appenders.set('std-log', defaultOpts)
|
||||
|
||||
export const serverLog = new Logger('glslangProvider')
|
||||
serverLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
export const serverLog = new Logger('server')
|
||||
serverLog.appenders.set('std-log', defaultOpts)
|
||||
|
||||
export const linkLog = new Logger('glslangProvider')
|
||||
linkLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
export const linkLog = new Logger('links')
|
||||
linkLog.appenders.set('std-log', defaultOpts)
|
||||
|
||||
export const uriLog = new Logger('glslangProvider')
|
||||
uriLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
export const uriLog = new Logger('uri')
|
||||
uriLog.appenders.set('std-log', defaultOpts)
|
||||
|
||||
// not added to loggers as this should always log changes
|
||||
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}`)
|
||||
return uri
|
||||
}
|
||||
|
||||
return ''
|
||||
// TODO windows
|
||||
return uri.replace(/^file:\/\//, '').replace(/\\/, '/')
|
||||
}
|
||||
|
||||
public static toFileURI(uri: string): string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue