diff options
Diffstat (limited to 'lib/extension.ts')
-rw-r--r-- | lib/extension.ts | 176 |
1 files changed, 78 insertions, 98 deletions
diff --git a/lib/extension.ts b/lib/extension.ts index ef9db39..706e440 100644 --- a/lib/extension.ts +++ b/lib/extension.ts @@ -4,7 +4,6 @@ import * as VSCode from "vscode"; import * as Path from "path"; import * as FS from "fs"; -import * as ChildProcess from "child_process"; import {LanguageClient, LanguageClientOptions, ServerOptions} from "vscode-languageclient"; /** Called when extension is activated */ @@ -18,107 +17,88 @@ export function activate(context: VSCode.ExtensionContext) { return; } - - isJava8(javaExecutablePath).then(eight => { - if (!eight) { - VSCode.window.showErrorMessage('Java language support requires Java 8 (using ' + javaExecutablePath + ')'); - - return; - } - - // Options to control the language client - let clientOptions: LanguageClientOptions = { - // Register the server for java documents - documentSelector: ['java'], - synchronize: { - // Synchronize the setting section 'java' to the server - // NOTE: this currently doesn't do anything - configurationSection: 'java', - // Notify the server about file changes to 'javaconfig.json' files contain in the workspace - fileEvents: [ - VSCode.workspace.createFileSystemWatcher('**/javaconfig.json'), - VSCode.workspace.createFileSystemWatcher('**/pom.xml'), - VSCode.workspace.createFileSystemWatcher('**/WORKSPACE'), - VSCode.workspace.createFileSystemWatcher('**/BUILD'), - VSCode.workspace.createFileSystemWatcher('**/*.java') - ] - }, - outputChannelName: 'Java', - revealOutputChannelOn: 4 // never - } - - let fatJar = Path.resolve(context.extensionPath, "out", "fat-jar.jar"); - - let args = [ - '-cp', fatJar, - '-Xverify:none', // helps VisualVM avoid 'error 62' - 'org.javacs.Main' - ]; - - console.log(javaExecutablePath + ' ' + args.join(' ')); - // Start the child java process - let serverOptions: ServerOptions = { - command: javaExecutablePath, - args: args, - options: { cwd: VSCode.workspace.rootPath } - } - - console.log(javaExecutablePath + ' ' + args.join(' ')); - - // Copied from typescript - VSCode.languages.setLanguageConfiguration('java', { - indentationRules: { - // ^(.*\*/)?\s*\}.*$ - decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/, - // ^.*\{[^}"']*$ - increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/, - indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/ - }, - onEnterRules: [ - { - // e.g. /** | */ - beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/, - afterText: /^\s*\*\/$/, - action: { indentAction: VSCode.IndentAction.IndentOutdent, appendText: ' * ' } - }, { - // e.g. /** ...| - beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/, - action: { indentAction: VSCode.IndentAction.None, appendText: ' * ' } - }, { - // e.g. * ...| - beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/, - action: { indentAction: VSCode.IndentAction.None, appendText: '* ' } - }, { - // e.g. */| - beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/, - action: { indentAction: VSCode.IndentAction.None, removeText: 1 } - }, - { - // e.g. *-----*/| - beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/, - action: { indentAction: VSCode.IndentAction.None, removeText: 1 } - } + // Options to control the language client + let clientOptions: LanguageClientOptions = { + // Register the server for java documents + documentSelector: ['java'], + synchronize: { + // Synchronize the setting section 'java' to the server + // NOTE: this currently doesn't do anything + configurationSection: 'java', + // Notify the server about file changes to 'javaconfig.json' files contain in the workspace + fileEvents: [ + VSCode.workspace.createFileSystemWatcher('**/javaconfig.json'), + VSCode.workspace.createFileSystemWatcher('**/pom.xml'), + VSCode.workspace.createFileSystemWatcher('**/WORKSPACE'), + VSCode.workspace.createFileSystemWatcher('**/BUILD'), + VSCode.workspace.createFileSystemWatcher('**/*.java') ] - }) + }, + outputChannelName: 'Java', + revealOutputChannelOn: 4 // never + } + + let fatJar = Path.resolve(context.extensionPath, "out", "fat-jar.jar"); - // Create the language client and start the client. - let languageClient = new LanguageClient('java', 'Java Language Server', serverOptions, clientOptions); - let disposable = languageClient.start(); + let args = [ + '-cp', fatJar, + '-Xverify:none', // helps VisualVM avoid 'error 62' + 'org.javacs.Main' + ]; - // Push the disposable to the context's subscriptions so that the - // client can be deactivated on extension deactivation - context.subscriptions.push(disposable); - }); -} + console.log(javaExecutablePath + ' ' + args.join(' ')); + // Start the child java process + let serverOptions: ServerOptions = { + command: javaExecutablePath, + args: args, + options: { cwd: VSCode.workspace.rootPath } + } -function isJava8(javaExecutablePath: string): Promise<boolean> { - return new Promise((resolve, reject) => { - ChildProcess.execFile(javaExecutablePath, ['-version'], { }, (error, stdout, stderr) => { - let eight = stderr.indexOf('1.8') >= 0, nine = stderr.indexOf('"9"') >= 0; - - resolve(eight || nine); - }); - }); + console.log(javaExecutablePath + ' ' + args.join(' ')); + + // Copied from typescript + VSCode.languages.setLanguageConfiguration('java', { + indentationRules: { + // ^(.*\*/)?\s*\}.*$ + decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/, + // ^.*\{[^}"']*$ + increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/, + indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/ + }, + onEnterRules: [ + { + // e.g. /** | */ + beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/, + afterText: /^\s*\*\/$/, + action: { indentAction: VSCode.IndentAction.IndentOutdent, appendText: ' * ' } + }, { + // e.g. /** ...| + beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/, + action: { indentAction: VSCode.IndentAction.None, appendText: ' * ' } + }, { + // e.g. * ...| + beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/, + action: { indentAction: VSCode.IndentAction.None, appendText: '* ' } + }, { + // e.g. */| + beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/, + action: { indentAction: VSCode.IndentAction.None, removeText: 1 } + }, + { + // e.g. *-----*/| + beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/, + action: { indentAction: VSCode.IndentAction.None, removeText: 1 } + } + ] + }) + + // Create the language client and start the client. + let languageClient = new LanguageClient('java', 'Java Language Server', serverOptions, clientOptions); + let disposable = languageClient.start(); + + // Push the disposable to the context's subscriptions so that the + // client can be deactivated on extension deactivation + context.subscriptions.push(disposable); } function findJavaExecutable(binname: string) { |