Skip to content

Commit 248afcd

Browse files
committed
adds custom file association support to filesystem event watcher
1 parent c854093 commit 248afcd

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66

77
## Unreleased
88

9+
### Added
10+
11+
- Filesystem watcher reads custom defined file associations
12+
913
### Fixed
1014

11-
- Fixed `#include` merging for when file is merged twice that would normally be `#ifdef` guarded. Please see commit message of [551380a](https://github.com/Strum355/mcshader-lsp/commit/551380a6ed00709287460b7d8c88e7803956052c) for detailed explanation.
15+
- Fixed `#include` merging for when file is merged twice that would normally be `#ifdef` guarded. Please see commit message of [551380a](https://github.com/Strum355/mcshader-lsp/commit/551380a6ed00709287460b7d8c88e7803956052c) for detailed explanation
1216

1317
## [0.9.4]
1418

client/src/extension.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,38 @@ export class Extension {
4545
this.registerCommand('virtualMerge', commands.virtualMergedDocument)
4646

4747
log.info('starting language server...')
48+
49+
const lspBinary = process.env['MCSHADER_DEBUG'] ?
50+
this.context.asAbsolutePath(path.join('server', 'target', 'debug', 'mcshader-lsp')) +
51+
(process.platform === 'win32' ? '.exe' : '') :
52+
path.join(this.context.globalStoragePath, 'mcshader-lsp')
53+
54+
const filewatcherGlob = this.fileAssociationsToGlob(this.getGLSLFileAssociations())
4855

49-
this.client = await new LanguageClient(this).startServer()
56+
this.client = await new LanguageClient(this, lspBinary, filewatcherGlob).startServer()
5057

5158
log.info('language server started!')
5259
}
5360

61+
fileAssociationsToGlob = (associations: string[]): string => {
62+
return '**/*.{'.concat(
63+
associations.map(s => s.substring(s.indexOf('.'))).join(',')
64+
) + '}'
65+
}
66+
67+
getGLSLFileAssociations = (): string[] => {
68+
const exts = ['.fsh', '.vsh', '.gsh', '.glsl']
69+
const associations = vscode.workspace.getConfiguration('files').get('associations') as {[key: string]: string}
70+
71+
Object.keys(associations).forEach((key) => {
72+
if(associations[key] === 'glsl') {
73+
exts.push(key.substring(key.indexOf('*')+1))
74+
}
75+
})
76+
77+
return exts
78+
}
79+
5480
registerCommand = (name: string, f: (e: Extension) => commands.Command) => {
5581
const cmd = f(this)
5682
this.context.subscriptions.push(vscode.commands.registerCommand('mcglsl.'+name, cmd))
@@ -83,7 +109,7 @@ export class Extension {
83109
if (!exists) await this.state.updateServerVersion(undefined)
84110

85111
const release = await getReleaseInfo(this.package.version)
86-
log.info(`got release info from Github:\n\t`, JSON.stringify(release))
112+
log.info('got release info from Github:\n\t', JSON.stringify(release))
87113

88114
const platform = platforms[`${process.arch} ${process.platform}`]
89115
if (platform === undefined) {
@@ -93,7 +119,7 @@ export class Extension {
93119
}
94120

95121
if (release.tag_name === this.state.serverVersion) {
96-
log.info(`server version is same as extension:\n\t`, this.state.serverVersion)
122+
log.info('server version is same as extension:\n\t', this.state.serverVersion)
97123
return
98124
}
99125

client/src/lspClient.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
import * as path from 'path'
21
import { ConfigurationTarget, workspace } from 'vscode'
32
import * as lsp from 'vscode-languageclient'
43
import { Extension } from './extension'
5-
import { lspOutputChannel } from './log'
4+
import { log, lspOutputChannel } from './log'
65
import { ConfigUpdateParams, statusMethod, StatusParams, updateConfigMethod } from './lspExt'
76

87
export class LanguageClient extends lsp.LanguageClient {
98
private extension: Extension
109

11-
constructor(ext: Extension) {
10+
constructor(ext: Extension, lspBinary: string, filewatcherGlob: string) {
1211
super('vscode-mc-shader', 'VSCode MC Shader', {
13-
command: process.env['MCSHADER_DEBUG'] ?
14-
ext.context.asAbsolutePath(path.join('server', 'target', 'debug', 'mcshader-lsp')) +
15-
(process.platform === 'win32' ? '.exe' : '') :
16-
path.join(ext.context.globalStoragePath, 'mcshader-lsp')
12+
command: lspBinary
1713
}, {
1814
documentSelector: [{scheme: 'file', language: 'glsl'}],
1915
outputChannel: lspOutputChannel,
2016
synchronize: {
2117
configurationSection: 'mcglsl',
22-
fileEvents: workspace.createFileSystemWatcher('**/*.{fsh,gsh,vsh,glsl,inc}')
18+
fileEvents: workspace.createFileSystemWatcher(filewatcherGlob)
2319
},
2420
})
2521
this.extension = ext
22+
23+
log.info('server receiving events for file glob:\n\t', filewatcherGlob)
24+
log.info('running with binary at path:\n\t', lspBinary)
2625
}
2726

2827
public startServer = async (): Promise<LanguageClient> => {

0 commit comments

Comments
 (0)