-
-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
166 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as vscode from 'vscode'; | ||
import { | ||
LanguageClient, | ||
RevealOutputChannelOn, | ||
ServerOptions, | ||
TransportKind, | ||
LanguageClientOptions | ||
} from 'vscode-languageclient'; | ||
|
||
export function initializeLanguageClient(serverModule: string): LanguageClient { | ||
const debugOptions = { execArgv: ['--nolazy', '--inspect=6005'] }; | ||
|
||
const serverOptions: ServerOptions = { | ||
run: { module: serverModule, transport: TransportKind.ipc }, | ||
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions } | ||
}; | ||
|
||
const documentSelector = ['vue']; | ||
const config = vscode.workspace.getConfiguration(); | ||
|
||
const clientOptions: LanguageClientOptions = { | ||
documentSelector, | ||
synchronize: { | ||
configurationSection: ['vetur', 'emmet', 'html', 'javascript', 'typescript', 'prettier', 'stylusSupremacy'], | ||
fileEvents: vscode.workspace.createFileSystemWatcher('{**/*.js,**/*.ts}', true, false, true) | ||
}, | ||
initializationOptions: { | ||
config | ||
}, | ||
revealOutputChannelOn: RevealOutputChannelOn.Never | ||
}; | ||
|
||
return new LanguageClient('vetur', 'Vue Language Server', serverOptions, clientOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { languages, IndentAction } from 'vscode'; | ||
|
||
const EMPTY_ELEMENTS: string[] = [ | ||
'area', | ||
'base', | ||
'br', | ||
'col', | ||
'embed', | ||
'hr', | ||
'img', | ||
'input', | ||
'keygen', | ||
'link', | ||
'menuitem', | ||
'meta', | ||
'param', | ||
'source', | ||
'track', | ||
'wbr' | ||
]; | ||
|
||
export function registerLanguageConfigurations() { | ||
languages.setLanguageConfiguration('vue-html', { | ||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g, | ||
onEnterRules: [ | ||
{ | ||
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), | ||
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i, | ||
action: { indentAction: IndentAction.IndentOutdent } | ||
}, | ||
{ | ||
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), | ||
action: { indentAction: IndentAction.Indent } | ||
} | ||
] | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,41 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import * as vscode from 'vscode'; | ||
import { languages, workspace, ExtensionContext, IndentAction } from 'vscode'; | ||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
TransportKind, | ||
RevealOutputChannelOn | ||
} from 'vscode-languageclient'; | ||
import { getGeneratedGrammar } from './grammar'; | ||
|
||
const EMPTY_ELEMENTS: string[] = [ | ||
'area', | ||
'base', | ||
'br', | ||
'col', | ||
'embed', | ||
'hr', | ||
'img', | ||
'input', | ||
'keygen', | ||
'link', | ||
'menuitem', | ||
'meta', | ||
'param', | ||
'source', | ||
'track', | ||
'wbr' | ||
]; | ||
import { LanguageClient } from 'vscode-languageclient'; | ||
import { generateGrammarCommandHandler } from './grammar'; | ||
import { registerLanguageConfigurations } from './languages'; | ||
import { initializeLanguageClient } from './client'; | ||
|
||
export function activate(context: ExtensionContext) { | ||
export function activate(context: vscode.ExtensionContext) { | ||
/** | ||
* Custom Block Grammar generation command | ||
*/ | ||
context.subscriptions.push( | ||
vscode.commands.registerCommand('vetur.generateGrammar', () => { | ||
const customBlocks: { [k: string]: string } = | ||
workspace.getConfiguration().get('vetur.grammar.customBlocks') || {}; | ||
try { | ||
const generatedGrammar = getGeneratedGrammar( | ||
path.resolve(context.extensionPath, 'syntaxes/vue.json'), | ||
customBlocks | ||
); | ||
fs.writeFileSync(path.resolve(context.extensionPath, 'syntaxes/vue-generated.json'), generatedGrammar, 'utf-8'); | ||
vscode.window.showInformationMessage('Successfully generated vue grammar. Reload VS Code to enable it.'); | ||
} catch (e) { | ||
vscode.window.showErrorMessage( | ||
'Failed to generate vue grammar. `vetur.grammar.customBlocks` contain invalid language values' | ||
); | ||
} | ||
}) | ||
vscode.commands.registerCommand('vetur.generateGrammar', generateGrammarCommandHandler(context.extensionPath)) | ||
); | ||
|
||
registerLanguageConfigurations(); | ||
|
||
/** | ||
* Vue Language Server Initialization | ||
*/ | ||
const serverModule = context.asAbsolutePath(path.join('server', 'dist', 'vueServerMain.js')); | ||
const debugOptions = { execArgv: ['--nolazy', '--inspect=6005'] }; | ||
|
||
const serverOptions: ServerOptions = { | ||
run: { module: serverModule, transport: TransportKind.ipc }, | ||
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions } | ||
}; | ||
|
||
const documentSelector = ['vue']; | ||
const config = workspace.getConfiguration(); | ||
|
||
const clientOptions: LanguageClientOptions = { | ||
documentSelector, | ||
synchronize: { | ||
configurationSection: ['vetur', 'emmet', 'html', 'javascript', 'typescript', 'prettier', 'stylusSupremacy'], | ||
fileEvents: vscode.workspace.createFileSystemWatcher('{**/*.js,**/*.ts}', true, false, true) | ||
}, | ||
initializationOptions: { | ||
config | ||
}, | ||
revealOutputChannelOn: RevealOutputChannelOn.Never | ||
}; | ||
|
||
const client = new LanguageClient('vetur', 'Vue Language Server', serverOptions, clientOptions); | ||
const disposable = client.start(); | ||
context.subscriptions.push(disposable); | ||
const serverModule = context.asAbsolutePath(path.join('server', 'dist', 'vueServerMain.js')); | ||
const client = initializeLanguageClient(serverModule); | ||
context.subscriptions.push(client.start()); | ||
|
||
languages.setLanguageConfiguration('vue-html', { | ||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g, | ||
onEnterRules: [ | ||
{ | ||
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), | ||
afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i, | ||
action: { indentAction: IndentAction.IndentOutdent } | ||
}, | ||
{ | ||
beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join('|')}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'), | ||
action: { indentAction: IndentAction.Indent } | ||
} | ||
] | ||
client.onReady().then(() => { | ||
registerCustomClientNotificationHandlers(client); | ||
}); | ||
} | ||
|
||
function registerCustomClientNotificationHandlers(client: LanguageClient) { | ||
client.onNotification('$/displayInfo', (msg: string) => { | ||
vscode.window.showInformationMessage(msg); | ||
}); | ||
client.onNotification('$/displayWarning', (msg: string) => { | ||
vscode.window.showWarningMessage(msg); | ||
}); | ||
client.onNotification('$/displayError', (msg: string) => { | ||
vscode.window.showErrorMessage(msg); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters