Skip to content

Commit

Permalink
Improve(VSCode): Restart and pop up notification when settings are ch…
Browse files Browse the repository at this point in the history
…anged
  • Loading branch information
1aron committed May 3, 2024
1 parent 0f94019 commit a490d55
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
47 changes: 36 additions & 11 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"directory": "packages/vscode"
},
"engines": {
"vscode": "^1.86.0"
"vscode": "^1.8.0"
},
"activationEvents": [
"onStartupFinished"
Expand Down Expand Up @@ -171,14 +171,38 @@
"masterCSS.classAttributeBindings": {
"type": "object",
"default": {
"className": [ "{", "}" ],
"class": [ "{", "}" ],
"class:list": [ "{", "}" ],
":class": [ "\"", "\"" ],
"v-bind:class": [ "\"", "\"" ],
"[class]": [ "\"", "\"" ],
"[className]": [ "\"", "\"" ],
"[ngClass]": [ "\"", "\"" ]
"className": [
"{",
"}"
],
"class": [
"{",
"}"
],
"class:list": [
"{",
"}"
],
":class": [
"\"",
"\""
],
"v-bind:class": [
"\"",
"\""
],
"[class]": [
"\"",
"\""
],
"[className]": [
"\"",
"\""
],
"[ngClass]": [
"\"",
"\""
]
}
},
"masterCSS.classDeclarations": {
Expand Down Expand Up @@ -227,9 +251,10 @@
"provenance": true
},
"devDependencies": {
"@master/css-shared": "workspace:^",
"@master/css-language-server": "workspace:^",
"@master/css-shared": "workspace:^",
"@types/vscode": "^1.87.0",
"@vscode/vsce": "^2.24.0",
"vscode-languageclient": "^7.0.0"
"vscode-languageclient": "^8.1.0"
}
}
33 changes: 26 additions & 7 deletions packages/vscode/src/extension.min.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import path from 'path'
import * as vscode from 'vscode'
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node'
import { commands, ExtensionContext, ProgressLocation, window, workspace } from 'vscode'
import { settings } from '@master/css-language-server'

let client: LanguageClient

const disposables: Disposable[] = []

export function activate(context: vscode.ExtensionContext) {
export function activate(context: ExtensionContext) {

// The server is implemented in node
const serverModule = context.asAbsolutePath(path.join('dist', 'server.min.cjs'))
console.log('Loading server from ', serverModule)

// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
Expand All @@ -26,7 +28,7 @@ export function activate(context: vscode.ExtensionContext) {
}
}

const includedLanguages = vscode.workspace.getConfiguration('masterCSS').includedLanguages
const includedLanguages = workspace.getConfiguration('masterCSS').includedLanguages
const Languages: { scheme: 'file', language: string }[] = []
includedLanguages.forEach((x: any) => {
Languages.push({ scheme: 'file', language: x })
Expand All @@ -38,7 +40,7 @@ export function activate(context: vscode.ExtensionContext) {
documentSelector: Languages,
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: vscode.workspace.createFileSystemWatcher('**/.clientrc')
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
}
}

Expand All @@ -52,10 +54,27 @@ export function activate(context: vscode.ExtensionContext) {

// Start the client. This will also launch the server
client.start()

context.subscriptions.push(
vscode.commands.registerCommand('masterCSS.restart', () => {
client.stop().then(() => client.start())
commands.registerCommand('masterCSS.restart', async () => {
window.withProgress({
location: ProgressLocation.Notification,
title: 'Restarting Master CSS Language Server...',
}, async () => await client.restart())
}),
workspace.onDidChangeConfiguration(async (event) => {
const affectedProperties = []
for (const optionName in settings) {
const property = `masterCSS.${optionName}`
if (event.affectsConfiguration(property)) {
affectedProperties.push(property)
}
}
if (affectedProperties.length) {
window.withProgress({
location: ProgressLocation.Notification,
title: `Updating for "${affectedProperties}" ...`,
}, async () => await client.restart())
}
})
)
}
Expand Down
6 changes: 5 additions & 1 deletion packages/vscode/src/server.min.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ import CSSLanguageServer from '@master/css-language-server'

const server = new CSSLanguageServer()

server.connection.listen()
server.connection.listen()

process.on('unhandledRejection', (e) => {
console.error(`Unhandled rejection`, e)
})

0 comments on commit a490d55

Please sign in to comment.