mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 09:59:25 +00:00
add option to allow language server to be shutdown
This commit is contained in:
50
extension.js
50
extension.js
@@ -8,13 +8,10 @@ const { openLogcatWindow } = require('./src/logcat');
|
|||||||
const { selectAndroidProcessID } = require('./src/process-attach');
|
const { selectAndroidProcessID } = require('./src/process-attach');
|
||||||
const { selectTargetDevice } = require('./src/utils/device');
|
const { selectTargetDevice } = require('./src/utils/device');
|
||||||
|
|
||||||
/** @type {LanguageClient} */
|
|
||||||
let client;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {vscode.ExtensionContext} context
|
* @param {vscode.ExtensionContext} context
|
||||||
*/
|
*/
|
||||||
function activateLanguageClient(context) {
|
function createLanguageClient(context) {
|
||||||
// The server is implemented in node
|
// The server is implemented in node
|
||||||
let serverModule = context.asAbsolutePath(path.join('langserver', 'server.js'));
|
let serverModule = context.asAbsolutePath(path.join('langserver', 'server.js'));
|
||||||
// The debug options for the server
|
// The debug options for the server
|
||||||
@@ -39,8 +36,10 @@ function activateLanguageClient(context) {
|
|||||||
// Options to control the language client
|
// Options to control the language client
|
||||||
/** @type {import('vscode-languageclient').LanguageClientOptions} */
|
/** @type {import('vscode-languageclient').LanguageClientOptions} */
|
||||||
let clientOptions = {
|
let clientOptions = {
|
||||||
// Register the server for plain text documents
|
// Register the server for Java source documents
|
||||||
documentSelector: [{ scheme: 'file', language: 'java' }],
|
documentSelector: [{
|
||||||
|
scheme: 'file', language: 'java'
|
||||||
|
}],
|
||||||
initializationOptions: {
|
initializationOptions: {
|
||||||
// extensionPath points to the root of the extension (the folder where this file is)
|
// extensionPath points to the root of the extension (the folder where this file is)
|
||||||
extensionPath: context.extensionPath,
|
extensionPath: context.extensionPath,
|
||||||
@@ -51,16 +50,36 @@ function activateLanguageClient(context) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the language client and start the client.
|
// Create the language client - this won't do anything until start() is called
|
||||||
client = new LanguageClient(
|
return new LanguageClient(
|
||||||
'androidJavaLanguageServer',
|
'androidJavaLanguageServer',
|
||||||
'Android',
|
'Android',
|
||||||
serverOptions,
|
serverOptions,
|
||||||
clientOptions
|
clientOptions
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Start the client. This will also launch the server
|
/** @type {LanguageClient} */
|
||||||
return client.start();
|
let languageClient;
|
||||||
|
let languageSupportEnabled = false;
|
||||||
|
function refreshLanguageServerEnabledState() {
|
||||||
|
let langSupport = vscode.workspace.getConfiguration('android-dev-ext').get('languageSupport', false);
|
||||||
|
if (langSupport === languageSupportEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (langSupport) {
|
||||||
|
if (languageClient.needsStart()) {
|
||||||
|
languageClient.start();
|
||||||
|
}
|
||||||
|
languageSupportEnabled = true;
|
||||||
|
} else {
|
||||||
|
if (languageClient.needsStop()) {
|
||||||
|
languageClient.stop().then(() => {
|
||||||
|
languageSupportEnabled = false;
|
||||||
|
refreshLanguageServerEnabledState();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,6 +90,9 @@ function activate(context) {
|
|||||||
/* Only the logcat stuff is configured here. The debugger is launched from src/debugMain.js */
|
/* Only the logcat stuff is configured here. The debugger is launched from src/debugMain.js */
|
||||||
AndroidContentProvider.register(context, vscode.workspace);
|
AndroidContentProvider.register(context, vscode.workspace);
|
||||||
|
|
||||||
|
languageClient = createLanguageClient(context);
|
||||||
|
refreshLanguageServerEnabledState();
|
||||||
|
|
||||||
// The commandId parameter must match the command field in package.json
|
// The commandId parameter must match the command field in package.json
|
||||||
const disposables = [
|
const disposables = [
|
||||||
// add the view logcat handler
|
// add the view logcat handler
|
||||||
@@ -109,7 +131,13 @@ function activate(context) {
|
|||||||
return JSON.stringify(o);
|
return JSON.stringify(o);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
activateLanguageClient(context),
|
vscode.workspace.onDidChangeConfiguration(e => {
|
||||||
|
// perform the refresh on the next tick to prevent spurious errors when
|
||||||
|
// trying to shut down the language server in the middle of a change-configuration request
|
||||||
|
process.nextTick(() => refreshLanguageServerEnabledState());
|
||||||
|
}),
|
||||||
|
|
||||||
|
languageClient,
|
||||||
];
|
];
|
||||||
|
|
||||||
context.subscriptions.splice(context.subscriptions.length, 0, ...disposables);
|
context.subscriptions.splice(context.subscriptions.length, 0, ...disposables);
|
||||||
|
|||||||
@@ -33,6 +33,12 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "Android",
|
"title": "Android",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"android-dev-ext.languageSupport": {
|
||||||
|
"scope": "resource",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": "true",
|
||||||
|
"description": "Enable Java language support for Android"
|
||||||
|
},
|
||||||
"android-dev-ext.appSourceRoot": {
|
"android-dev-ext.appSourceRoot": {
|
||||||
"scope": "resource",
|
"scope": "resource",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|||||||
Reference in New Issue
Block a user