mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-04 17:08:42 +00:00
adds custom file association support to filesystem event watcher
This commit is contained in:
parent
c854093a96
commit
248afcd988
3 changed files with 41 additions and 12 deletions
|
@ -45,12 +45,38 @@ export class Extension {
|
|||
this.registerCommand('virtualMerge', commands.virtualMergedDocument)
|
||||
|
||||
log.info('starting language server...')
|
||||
|
||||
const lspBinary = process.env['MCSHADER_DEBUG'] ?
|
||||
this.context.asAbsolutePath(path.join('server', 'target', 'debug', 'mcshader-lsp')) +
|
||||
(process.platform === 'win32' ? '.exe' : '') :
|
||||
path.join(this.context.globalStoragePath, 'mcshader-lsp')
|
||||
|
||||
const filewatcherGlob = this.fileAssociationsToGlob(this.getGLSLFileAssociations())
|
||||
|
||||
this.client = await new LanguageClient(this).startServer()
|
||||
this.client = await new LanguageClient(this, lspBinary, filewatcherGlob).startServer()
|
||||
|
||||
log.info('language server started!')
|
||||
}
|
||||
|
||||
fileAssociationsToGlob = (associations: string[]): string => {
|
||||
return '**/*.{'.concat(
|
||||
associations.map(s => s.substring(s.indexOf('.'))).join(',')
|
||||
) + '}'
|
||||
}
|
||||
|
||||
getGLSLFileAssociations = (): string[] => {
|
||||
const exts = ['.fsh', '.vsh', '.gsh', '.glsl']
|
||||
const associations = vscode.workspace.getConfiguration('files').get('associations') as {[key: string]: string}
|
||||
|
||||
Object.keys(associations).forEach((key) => {
|
||||
if(associations[key] === 'glsl') {
|
||||
exts.push(key.substring(key.indexOf('*')+1))
|
||||
}
|
||||
})
|
||||
|
||||
return exts
|
||||
}
|
||||
|
||||
registerCommand = (name: string, f: (e: Extension) => commands.Command) => {
|
||||
const cmd = f(this)
|
||||
this.context.subscriptions.push(vscode.commands.registerCommand('mcglsl.'+name, cmd))
|
||||
|
@ -83,7 +109,7 @@ export class Extension {
|
|||
if (!exists) await this.state.updateServerVersion(undefined)
|
||||
|
||||
const release = await getReleaseInfo(this.package.version)
|
||||
log.info(`got release info from Github:\n\t`, JSON.stringify(release))
|
||||
log.info('got release info from Github:\n\t', JSON.stringify(release))
|
||||
|
||||
const platform = platforms[`${process.arch} ${process.platform}`]
|
||||
if (platform === undefined) {
|
||||
|
@ -93,7 +119,7 @@ export class Extension {
|
|||
}
|
||||
|
||||
if (release.tag_name === this.state.serverVersion) {
|
||||
log.info(`server version is same as extension:\n\t`, this.state.serverVersion)
|
||||
log.info('server version is same as extension:\n\t', this.state.serverVersion)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,28 +1,27 @@
|
|||
import * as path from 'path'
|
||||
import { ConfigurationTarget, workspace } from 'vscode'
|
||||
import * as lsp from 'vscode-languageclient'
|
||||
import { Extension } from './extension'
|
||||
import { lspOutputChannel } from './log'
|
||||
import { log, lspOutputChannel } from './log'
|
||||
import { ConfigUpdateParams, statusMethod, StatusParams, updateConfigMethod } from './lspExt'
|
||||
|
||||
export class LanguageClient extends lsp.LanguageClient {
|
||||
private extension: Extension
|
||||
|
||||
constructor(ext: Extension) {
|
||||
constructor(ext: Extension, lspBinary: string, filewatcherGlob: string) {
|
||||
super('vscode-mc-shader', 'VSCode MC Shader', {
|
||||
command: process.env['MCSHADER_DEBUG'] ?
|
||||
ext.context.asAbsolutePath(path.join('server', 'target', 'debug', 'mcshader-lsp')) +
|
||||
(process.platform === 'win32' ? '.exe' : '') :
|
||||
path.join(ext.context.globalStoragePath, 'mcshader-lsp')
|
||||
command: lspBinary
|
||||
}, {
|
||||
documentSelector: [{scheme: 'file', language: 'glsl'}],
|
||||
outputChannel: lspOutputChannel,
|
||||
synchronize: {
|
||||
configurationSection: 'mcglsl',
|
||||
fileEvents: workspace.createFileSystemWatcher('**/*.{fsh,gsh,vsh,glsl,inc}')
|
||||
fileEvents: workspace.createFileSystemWatcher(filewatcherGlob)
|
||||
},
|
||||
})
|
||||
this.extension = ext
|
||||
|
||||
log.info('server receiving events for file glob:\n\t', filewatcherGlob)
|
||||
log.info('running with binary at path:\n\t', lspBinary)
|
||||
}
|
||||
|
||||
public startServer = async (): Promise<LanguageClient> => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue