mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-24 11:44:44 +00:00
Moved to better logging lib
This commit is contained in:
parent
ffa0007c51
commit
b8acc6837e
11 changed files with 179 additions and 73 deletions
|
@ -1,8 +1,8 @@
|
|||
import { connection } from './server'
|
||||
import { serverLog as log } from './logging'
|
||||
import { dirname } from 'path'
|
||||
import { DidChangeConfigurationParams } from 'vscode-languageserver'
|
||||
import { GLSLangProvider } from './glslangValidator'
|
||||
import { serverLog as log } from './logging'
|
||||
import { connection } from './server'
|
||||
|
||||
const url = {
|
||||
'win32': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip',
|
||||
|
@ -69,18 +69,18 @@ interface Config {
|
|||
let supress = false
|
||||
|
||||
async function onConfigChange(confProv: ConfigProvider, old: Config) {
|
||||
if (!confProv.config == undefined &&
|
||||
old.shaderpacksPath === confProv.config.shaderpacksPath &&
|
||||
if (!confProv.config == undefined &&
|
||||
old.shaderpacksPath === confProv.config.shaderpacksPath &&
|
||||
old.glslangValidatorPath === confProv.config.glslangValidatorPath) 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(old))
|
||||
log.debug('old config: ' + JSON.stringify(confProv.config))
|
||||
|
||||
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'`, null)
|
||||
log.error(`shaderpack path '${confProv.config.shaderpacksPath.replace(dirname(confProv.config.shaderpacksPath), '')}' not set or doesn't end in 'shaderpacks'`)
|
||||
supress = true
|
||||
|
||||
const clicked = await connection.window.showErrorMessage(
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import * as unzip from 'adm-zip';
|
||||
import { execSync } from 'child_process';
|
||||
import { writeFileSync } from 'fs';
|
||||
import fetch from 'node-fetch';
|
||||
import { platform } from 'os';
|
||||
import { ConfigProvider } from './config';
|
||||
import { extensionMap, ShaderFileExtension } from './fileTypes';
|
||||
import { glslProviderLog as log } from './logging';
|
||||
import { connection } from './server';
|
||||
|
||||
import * as unzip from 'adm-zip'
|
||||
import { execSync } from 'child_process'
|
||||
import { writeFileSync } from 'fs'
|
||||
import fetch from 'node-fetch'
|
||||
import { platform } from 'os'
|
||||
import { ConfigProvider } from './config'
|
||||
import { extensionMap, ShaderFileExtension } from './fileTypes'
|
||||
import { glslProviderLog as log } from './logging'
|
||||
import { connection } from './server'
|
||||
|
||||
const url = {
|
||||
'win32': 'https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip',
|
||||
|
@ -17,11 +16,11 @@ const url = {
|
|||
|
||||
export class GLSLangProvider {
|
||||
private _config: ConfigProvider
|
||||
|
||||
|
||||
public constructor(c: ConfigProvider) {
|
||||
this._config = c
|
||||
}
|
||||
|
||||
|
||||
public lint(document: string, fileExtension: ShaderFileExtension): string {
|
||||
try {
|
||||
execSync(`${this._config.config.glslangValidatorPath} --stdin -S ${extensionMap.get(fileExtension)}`, {input: document})
|
||||
|
@ -36,7 +35,7 @@ export class GLSLangProvider {
|
|||
{title: 'Download'},
|
||||
{title: 'Cancel'}
|
||||
)
|
||||
|
||||
|
||||
if (!chosen || chosen.title !== 'Download') return
|
||||
|
||||
await this.installExecutable()
|
||||
|
@ -48,11 +47,11 @@ export class GLSLangProvider {
|
|||
const glslangPath = this._config.config.shaderpacksPath + glslangBin
|
||||
|
||||
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 bin = zip.readFile('bin' + glslangBin)
|
||||
log.warn(() => 'buffer length ' + bin.length)
|
||||
log.info('buffer length ' + bin.length)
|
||||
writeFileSync(glslangPath, bin, {encoding: null, mode: 0o755})
|
||||
|
||||
if (!this.testExecutable()) {
|
||||
|
@ -62,20 +61,19 @@ export class GLSLangProvider {
|
|||
return
|
||||
}
|
||||
|
||||
// why doesnt this work????????
|
||||
log.info(() => `successfully downloaded glslangValidator to ${glslangPath}`)
|
||||
log.info(`successfully downloaded glslangValidator to ${glslangPath}`)
|
||||
connection.window.showInformationMessage(
|
||||
`glslangValidator has been downloaded to ${glslangPath}. Your config should be updated automatically.`
|
||||
)
|
||||
connection.sendNotification('update-config', glslangPath)
|
||||
} catch (e) {
|
||||
log.error(() => `failed downloading glslangValidator`, e)
|
||||
log.error(`failed downloading glslangValidator ${e}`)
|
||||
connection.window.showErrorMessage(
|
||||
`Failed to install glslangValidator: ${e}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public testExecutable(glslangPath?: string): boolean {
|
||||
let stdout = ''
|
||||
try {
|
||||
|
@ -86,13 +84,13 @@ export class GLSLangProvider {
|
|||
stdout = (e.stdout.toString() as string)
|
||||
}
|
||||
|
||||
log.warn(() => 'glslangValidator first line stdout: ' + stdout.split('\n')[0])
|
||||
log.warn('glslangValidator first line stdout: "' + stdout.split('\n')[0] + '"')
|
||||
const success = stdout.startsWith('Usage')
|
||||
|
||||
if (success) {
|
||||
log.info(() => `glslangValidator found at ${this._config.config.glslangValidatorPath}`)
|
||||
log.info(`glslangValidator found at ${this._config.config.glslangValidatorPath}`)
|
||||
} else {
|
||||
log.warn(() => `glslangValidator not found at ${this._config.config.glslangValidatorPath}`)
|
||||
log.warn(`glslangValidator not found at ${this._config.config.glslangValidatorPath}`)
|
||||
}
|
||||
|
||||
return success
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as vsclang from 'vscode-languageserver'
|
||||
import { linkLog as log} from './logging'
|
||||
import { linkLog as log } from './logging'
|
||||
import { formatURI } from './utils'
|
||||
|
||||
export function getDocumentLinks(file: string): vsclang.DocumentLink[] {
|
||||
log.debug(() => formatURI(file) + ' ' + file)
|
||||
log.debug(formatURI(file) + ' ' + file)
|
||||
return [vsclang.DocumentLink.create(vsclang.Range.create(8, 0, 8, 32), 'file:///e:\\shaderpacks\\Sushi-Shader\\shaders\\composite1.vsh')]
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
export class Linter {
|
||||
|
||||
|
||||
}
|
|
@ -88,23 +88,23 @@ export function preprocess(lines: string[], docURI: string) {
|
|||
|
||||
function includeDirective(lines: string[]): boolean {
|
||||
if (lines.findIndex(x => reIncludeExt.test(x)) > -1) {
|
||||
linterLog.info(() => 'include directive found')
|
||||
linterlog.info('include directive found')
|
||||
return true
|
||||
}
|
||||
|
||||
let hasDirective = true
|
||||
linterLog.info(() => 'include directive not found')
|
||||
linterlog.info('include directive not found')
|
||||
hasDirective = false
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i]
|
||||
if (reVersion.test(line)) {
|
||||
linterLog.info(() => 'found version on line ' + (i + 1))
|
||||
linterlog.info('found version on line ' + (i + 1))
|
||||
lines.splice(i + 1, 0, include)
|
||||
break
|
||||
}
|
||||
|
||||
/* if (i === lines.length - 1) {
|
||||
linterLog.warn(() => `no version found for ${docURI}. inserting at top`)
|
||||
linterlog.warn(`no version found for ${docURI}. inserting at top`)
|
||||
lines.splice(0, 0, include)
|
||||
break
|
||||
} */
|
||||
|
@ -129,7 +129,7 @@ function processIncludes(lines: string[], incStack: string[], allIncludes: Set<I
|
|||
const includeList = Array.from(includes.values())
|
||||
|
||||
if (includeList.length > 0) {
|
||||
linterLog.info(() => `${trimPath(parent)} has ${includeList.length} include(s). [${includeList.map(i => '\n\t\t' + trimPath(i.path))}\n\t]`)
|
||||
linterlog.info(`${trimPath(parent)} has ${includeList.length} include(s). [${includeList.map(i => '\n\t\t' + trimPath(i.path))}\n\t]`)
|
||||
|
||||
includeList.reverse().forEach(inc => {
|
||||
buildIncludeGraph(inc)
|
||||
|
@ -156,7 +156,7 @@ function processLine(includes: Map<string, IncludeObj>, line: string, lines: str
|
|||
const updated = Comment.update(line, linesInfo.comment)
|
||||
linesInfo.comment = updated[0]
|
||||
|
||||
if (updated[1] !== line) linterLog.debug(() => `change:\n\t'${line}'\n\t'${updated[1]}'`)
|
||||
if (updated[1] !== line) linterlog.debug(`change:\n\t'${line}'\n\t'${updated[1]}'`)
|
||||
|
||||
line = updated[1]
|
||||
lines[i] = line
|
||||
|
@ -273,12 +273,12 @@ function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnost
|
|||
if (diags.length === 0) return
|
||||
const errors = diags.filter(d => d.severity === DiagnosticSeverity.Error)
|
||||
const warnings = diags.filter(d => d.severity === DiagnosticSeverity.Warning)
|
||||
linterLog.info(() => `found ${errors.length} error(s) and ${warnings.length} warning(s) for ${trimPath(uri)}`)
|
||||
linterlog.info(`found ${errors.length} error(s) and ${warnings.length} warning(s) for ${trimPath(uri)}`)
|
||||
})
|
||||
|
||||
const diagsList = daigsArray(diagnostics)
|
||||
|
||||
if (diagsList.filter(d => d.diag.length > 0).length === 0) linterLog.info(() => 'no errors found')
|
||||
if (diagsList.filter(d => d.diag.length > 0).length === 0) linterlog.info('no errors found')
|
||||
|
||||
//console.log(JSON.stringify(diagsList.filter(d => d.diag.length > 0), null, 2))
|
||||
|
||||
|
@ -292,7 +292,7 @@ function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnost
|
|||
}
|
||||
|
||||
function processErrors(out: string, docURI: string, diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
|
||||
linterLog.debug(() => out.split('\n').filter(s => s.length > 2).join('\n'))
|
||||
linterlog.debug(out.split('\n').filter(s => s.length > 2).join('\n'))
|
||||
filterMatches(out).forEach(match => {
|
||||
const error: ErrorMatch = {
|
||||
type: errorType(match[1]),
|
||||
|
@ -349,7 +349,7 @@ const filterMatches = (output: string) => output
|
|||
.filter(match => match && match.length === 5)
|
||||
|
||||
function calcRange(lineNum: number, uri: string) {
|
||||
linterLog.debug(() => `calculating range for ${trimPath(uri)} at L${lineNum + 1}, index ${lineNum}`)
|
||||
linterlog.debug(`calculating range for ${trimPath(uri)} at L${lineNum + 1}, index ${lineNum}`)
|
||||
|
||||
const lines = getDocumentContents(uri).split('\n')
|
||||
const line = lines[Math.min(Math.max(lineNum, 0), lines.length - 1)]
|
||||
|
|
|
@ -1,11 +1,43 @@
|
|||
import { Category, CategoryConfiguration, CategoryServiceFactory, LogLevel } from 'typescript-logging'
|
||||
import { Logger } from 'ts-log-debug'
|
||||
|
||||
CategoryServiceFactory.setDefaultConfiguration(new CategoryConfiguration(LogLevel.Debug))
|
||||
export const glslProviderLog = new Logger('glslangProvider')
|
||||
glslProviderLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
|
||||
export const linterLog = new Logger('glslangProvider')
|
||||
linterLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
|
||||
export const linterLog = new Category('linter')
|
||||
export const completionLog = new Category('completion')
|
||||
export const serverLog = new Category('server')
|
||||
export const linkLog = new Category('links')
|
||||
export const glslProviderLog = new Category('glslangProvider')
|
||||
export const uriLog = new Category('uri')
|
||||
export const completionLog = new Logger('glslangProvider')
|
||||
completionLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
|
||||
export const serverLog = new Logger('glslangProvider')
|
||||
serverLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
|
||||
export const linkLog = new Logger('glslangProvider')
|
||||
linkLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
|
||||
export const uriLog = new Logger('glslangProvider')
|
||||
uriLog.appenders.set('std-log', {
|
||||
type: 'stdout',
|
||||
layout: {type: 'basic'},
|
||||
levels: ['info', 'warn', 'error']
|
||||
})
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as vsclangproto from 'vscode-languageserver-protocol'
|
|||
import { completions } from './completionProvider'
|
||||
import { ConfigProvider } from './config'
|
||||
import { getDocumentLinks } from './linksProvider'
|
||||
import { GLSLangProvider } from './glslangValidator';
|
||||
import { GLSLangProvider } from './glslangValidator'
|
||||
|
||||
const reVersion = /#version [\d]{3}/
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import { Category } from 'typescript-logging'
|
||||
import { platform } from 'os'
|
||||
import { uriLog as log } from './logging';
|
||||
|
||||
import { uriLog as log } from './logging'
|
||||
|
||||
export function formatURI(uri: string): string {
|
||||
const drive = uri[7]
|
||||
|
@ -11,14 +8,12 @@ export function formatURI(uri: string): string {
|
|||
|
||||
export class URI {
|
||||
public static fromFileURI(uri: string): string {
|
||||
log.debug(() => `normalizing ${uri}`)
|
||||
log.debug(`normalizing ${uri}`)
|
||||
if (URI.isNormalized(uri)) {
|
||||
log.debug(() => `already normalized ${uri}`)
|
||||
log.debug(`already normalized ${uri}`)
|
||||
return uri
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
|
@ -37,7 +32,7 @@ export class URI {
|
|||
fileURI = fileURI.replace('file://', 'file:///')
|
||||
}
|
||||
|
||||
log.debug(() => `formatted '${uri}' to '${fileURI}'`)
|
||||
log.debug(`formatted '${uri}' to '${fileURI}'`)
|
||||
return fileURI
|
||||
}
|
||||
|
||||
|
@ -49,4 +44,3 @@ export class URI {
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,10 @@
|
|||
import { readFileSync, FSWatcher, ReadStream } from 'fs'
|
||||
import * as urL from 'url'
|
||||
import { readFileSync } from 'fs'
|
||||
import { serverLog as log } from './logging'
|
||||
import { connection, documents } from './server'
|
||||
import { url } from 'inspector';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
export function postError(e: Error) {
|
||||
connection.window.showErrorMessage(e.message)
|
||||
log.error(() => e.message, null)
|
||||
log.error(e.message)
|
||||
}
|
||||
|
||||
export function formatURI(uri: string): string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue