Skip to content

Commit c733c58

Browse files
committed
move detection of language server ready to initialization of the server
1 parent 7b777cb commit c733c58

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@
216216
"type": "string",
217217
"enum": [
218218
"disabled",
219-
"external"
219+
"external"
220220
],
221221
"enumDescriptions": [
222222
"Do not open the result report",
223-
"Opens the report in an external browser."
223+
"Opens the report in an external browser."
224224
],
225225
"default": "none",
226226
"description": "Defines if the test report should be opened a run session automatically.",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mypy = "^0.790"
1818
flake8 = "^3.8.4"
1919
black = "^20.8b1"
2020
pep8-naming = "^0.11.1"
21-
debugpy = "^1.2.0"
21+
debugpy = "^1.2.1"
2222
pytest = "^6.2.1"
2323
pytest-asyncio = "^0.14.0"
2424
pytest-cov = "^2.11.1"

vscode-client/extension.ts

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const OUTPUT_CHANNEL = vscode.window.createOutputChannel(OUTPUT_CHANNEL_NAME);
1717
var extensionContext: vscode.ExtensionContext | undefined = undefined;
1818
var pythonLanguageServerMain: string | undefined;
1919
var pythonDebugAdapterMain: string | undefined;
20+
//var pythonDebugpyPath: string | undefined;
2021

2122
function getPythonCommand(folder: vscode.WorkspaceFolder | undefined): string | undefined {
2223
let config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
@@ -28,7 +29,7 @@ function getPythonCommand(folder: vscode.WorkspaceFolder | undefined): string |
2829
result = configPython;
2930
} else {
3031
const pythonExtension = vscode.extensions.getExtension("ms-python.python")!;
31-
let pythonExtensionPythonPath: string[] | undefined = pythonExtension.exports.settings.getExecutionDetails(
32+
let pythonExtensionPythonPath: string[] | undefined = pythonExtension?.exports?.settings?.getExecutionDetails(
3233
folder?.uri
3334
)?.execCommand;
3435

@@ -44,16 +45,6 @@ let clientsMutex = new Mutex();
4445
let clients: Map<string, LanguageClient> = new Map();
4546

4647
async function updateLoadedDocumentClients(uri?: vscode.Uri | undefined) {
47-
// if (uri && clients.has(uri.toString())) {
48-
// await clientsMutex.dispatch(async () => {
49-
// let client = clients.get(uri.toString());
50-
// clients.delete(uri.toString());
51-
// await client?.stop();
52-
// });
53-
54-
// await getLanguageClientForResource(uri);
55-
// }
56-
5748
OUTPUT_CHANNEL.appendLine("initialze/restart all needed language clients.");
5849
await clientsMutex.dispatch(async () => {
5950
for (let client of clients.values()) {
@@ -113,7 +104,7 @@ async function getLanguageClientForDocument(document: vscode.TextDocument): Prom
113104
}
114105

115106
async function getLanguageClientForResource(resource: string | vscode.Uri): Promise<LanguageClient | undefined> {
116-
var client = await clientsMutex.dispatch(async () => {
107+
return await clientsMutex.dispatch(async () => {
117108
let uri = resource instanceof vscode.Uri ? resource : vscode.Uri.parse(resource);
118109
let workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
119110

@@ -142,7 +133,7 @@ async function getLanguageClientForResource(resource: string | vscode.Uri): Prom
142133
{ scheme: "file", language: "robotframework", pattern: `${workspaceFolder.uri.fsPath}/**/*` },
143134
],
144135
synchronize: {
145-
configurationSection: [CONFIG_SECTION, "python"],
136+
configurationSection: [CONFIG_SECTION],
146137
},
147138
initializationOptions: {
148139
storageUri: extensionContext?.storageUri?.toString(),
@@ -167,13 +158,22 @@ async function getLanguageClientForResource(resource: string | vscode.Uri): Prom
167158
result.start();
168159

169160
result = await result.onReady().then(
170-
(_) => {
171-
OUTPUT_CHANNEL.appendLine(`client ${client?.clientOptions.workspaceFolder?.uri ?? "unknown"} ready.`);
161+
async (_) => {
162+
OUTPUT_CHANNEL.appendLine(`client ${result?.clientOptions.workspaceFolder?.uri ?? "unknown"} ready.`);
163+
var counter = 0;
164+
try {
165+
while (!result?.initializeResult && counter < 1000) {
166+
await sleep(10);
167+
counter++;
168+
}
169+
} catch {
170+
return undefined;
171+
}
172172
return result;
173173
},
174-
(reason) => {
174+
async (reason) => {
175175
OUTPUT_CHANNEL.appendLine(
176-
`client ${client?.clientOptions.workspaceFolder?.uri ?? "unknown"} error: ${reason}`
176+
`client ${result?.clientOptions.workspaceFolder?.uri ?? "unknown"} error: ${reason}`
177177
);
178178
vscode.window.showErrorMessage(reason.message ?? "Unknown error.");
179179
return undefined;
@@ -184,22 +184,6 @@ async function getLanguageClientForResource(resource: string | vscode.Uri): Prom
184184

185185
return result;
186186
});
187-
188-
if (client) {
189-
// be sure client is correctly initialized
190-
191-
var counter = 0;
192-
try {
193-
while (!client.initializeResult && counter < 1000) {
194-
await sleep(10);
195-
counter++;
196-
}
197-
} catch {
198-
return undefined;
199-
}
200-
}
201-
202-
return client;
203187
}
204188

205189
function getServerOptionsTCP(folder: vscode.WorkspaceFolder) {
@@ -287,6 +271,10 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
287271

288272
debugConfiguration.env = { ...config.get<Object>("robot.env", {}), ...(debugConfiguration.env ?? {}) };
289273

274+
// if (pythonDebugpyPath) {
275+
// debugConfiguration.env = { PYTHONPATH: path.dirname(pythonDebugpyPath), ...debugConfiguration.env };
276+
// }
277+
290278
if (!debugConfiguration.attachPython || debugConfiguration.noDebug) {
291279
debugConfiguration.attachPython = false;
292280
}
@@ -530,6 +518,8 @@ export async function activateAsync(context: vscode.ExtensionContext) {
530518

531519
await pythonExtension.activate();
532520

521+
//pythonDebugpyPath = await pythonExtension?.exports?.debug?.getDebuggerPackagePath();
522+
533523
OUTPUT_CHANNEL.appendLine("Python Extension is active");
534524

535525
context.subscriptions.push(

0 commit comments

Comments
 (0)