Skip to content

Commit 6519687

Browse files
committed
feat(vscode): introduce robotcode contribution point for vscode extensions plugins
1 parent f57b065 commit 6519687

File tree

6 files changed

+69
-24
lines changed

6 files changed

+69
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
],
107107
"configurationDefaults": {
108108
"[robotframework]": {
109-
"editor.wordBasedSuggestions": false,
109+
"editor.wordBasedSuggestions": "off",
110110
"editor.semanticHighlighting.enabled": true,
111111
"editor.inlayHints.enabled": "offUnlessPressed",
112112
"editor.quickSuggestionsDelay": 100,

packages/runner/src/robotcode/runner/cli/discover/discover.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def __init__(self, *args: Any, error_message: str, **kwargs: Any) -> None:
5959
__patched = False
6060

6161

62-
_stdin_data: Optional[Dict[str, str]] = None
62+
_stdin_data: Optional[Dict[Uri, str]] = None
63+
_app: Optional[Application] = None
6364

6465

6566
def _patch() -> None:
@@ -187,8 +188,9 @@ def _validate_execution_mode(self: SuiteStructureParser, suite: TestSuite) -> No
187188

188189
def get_file(self: FileReader, source: Union[str, Path, IOBase], accept_text: bool) -> Any:
189190
path = self._get_path(source, accept_text)
191+
190192
if path:
191-
if _stdin_data is not None and (data := _stdin_data.get(str(path))) is not None:
193+
if _stdin_data is not None and (data := _stdin_data.get(Uri.from_path(path))) is not None:
192194
if data is not None:
193195
return old_get_file(self, data, True)
194196

@@ -380,10 +382,14 @@ def discover(app: Application, show_diagnostics: bool, read_from_stdin: bool) ->
380382
robotcode --profile regression discover tests
381383
```
382384
"""
385+
global _app
386+
_app = app
383387
app.show_diagnostics = show_diagnostics or app.config.log_enabled
384388
if read_from_stdin:
385389
global _stdin_data
386-
_stdin_data = from_json(sys.stdin.buffer.read(), Dict[str, str], strict=True)
390+
_stdin_data = {
391+
Uri(k).normalized(): v for k, v in from_json(sys.stdin.buffer.read(), Dict[str, str], strict=True).items()
392+
}
387393
app.verbose(f"Read data from stdin: {_stdin_data!r}")
388394

389395

vscode-client/debugmanager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
6464
if (
6565
editor &&
6666
SUPPORTED_LANGUAGES.includes(editor.document.languageId) &&
67-
(editor.document.fileName.endsWith(".robot") || editor.document.fileName.endsWith(".feature"))
67+
editor.document.fileName.endsWith(".robot")
6868
) {
6969
const result = await vscode.window.showQuickPick(
7070
DEBUG_CONFIGURATIONS.map((v) => v),

vscode-client/languageclientsmanger.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export function toVsCodeRange(range: Range): vscode.Range {
3636
}
3737

3838
export const SUPPORTED_LANGUAGES = ["robotframework"];
39-
export const SUPPORTED_SUITE_FILE_EXTENSIONS = [".robot"];
4039

4140
export interface Keyword {
4241
name: string;
@@ -102,6 +101,15 @@ interface DiscoverInfoResult {
102101
[key: string]: string | undefined;
103102
}
104103

104+
interface RobotCodeContributions {
105+
contributes?: {
106+
robotCode?: {
107+
fileExtensions?: string[];
108+
languageIds?: string[];
109+
};
110+
};
111+
}
112+
105113
export class LanguageClientsManager {
106114
private clientsMutex = new Mutex();
107115
private _pythonValidPythonAndRobotEnvMutex = new Mutex();
@@ -120,9 +128,43 @@ export class LanguageClientsManager {
120128
return this._onClientStateChangedEmitter.event;
121129
}
122130

131+
private _supportedLanguages?: string[];
132+
133+
public get supportedLanguages(): string[] {
134+
if (this._supportedLanguages === undefined) {
135+
this._supportedLanguages = ["robotframework"];
136+
137+
vscode.extensions.all.forEach((extension) => {
138+
if (this._supportedLanguages !== undefined && extension.packageJSON !== undefined) {
139+
const ext = (extension.packageJSON as RobotCodeContributions)?.contributes?.robotCode?.languageIds;
140+
141+
if (ext !== undefined) {
142+
this._supportedLanguages.push(...ext);
143+
}
144+
}
145+
});
146+
}
147+
return this._supportedLanguages;
148+
}
149+
150+
private _fileExtensions?: string[];
151+
123152
// eslint-disable-next-line class-methods-use-this
124153
public get fileExtensions(): string[] {
125-
return ["robot", "resource"];
154+
if (this._fileExtensions === undefined) {
155+
this._fileExtensions = ["robot", "resource"];
156+
157+
vscode.extensions.all.forEach((extension) => {
158+
if (this._fileExtensions !== undefined && extension.packageJSON !== undefined) {
159+
const ext = (extension.packageJSON as RobotCodeContributions)?.contributes?.robotCode?.fileExtensions;
160+
161+
if (ext !== undefined) {
162+
this._fileExtensions.push(...ext);
163+
}
164+
}
165+
});
166+
}
167+
return this._fileExtensions;
126168
}
127169

128170
constructor(
@@ -375,7 +417,7 @@ export class LanguageClientsManager {
375417
}
376418

377419
public async getLanguageClientForDocument(document: vscode.TextDocument): Promise<LanguageClient | undefined> {
378-
if (!SUPPORTED_LANGUAGES.includes(document.languageId)) return;
420+
if (!this.supportedLanguages.includes(document.languageId)) return;
379421

380422
return this.getLanguageClientForResource(document.uri);
381423
}
@@ -613,7 +655,7 @@ export class LanguageClientsManager {
613655
}
614656

615657
for (const document of vscode.workspace.textDocuments) {
616-
if (SUPPORTED_LANGUAGES.includes(document.languageId)) {
658+
if (this.supportedLanguages.includes(document.languageId)) {
617659
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
618660
if (workspaceFolder) {
619661
folders.add(workspaceFolder);
@@ -728,7 +770,7 @@ export class LanguageClientsManager {
728770
}
729771

730772
private async updateStatusbarItem(editor: vscode.TextEditor | undefined) {
731-
if (editor && SUPPORTED_LANGUAGES.includes(editor.document.languageId)) {
773+
if (editor && this.supportedLanguages.includes(editor.document.languageId)) {
732774
try {
733775
const folder = vscode.workspace.getWorkspaceFolder(editor.document.uri);
734776
if (folder) {

vscode-client/pythonmanger.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ export class PythonManager {
233233

234234
process.stdout.on("data", (data) => {
235235
stdout += data;
236+
// this.outputChannel.appendLine(data as string);
236237
});
237238

238239
process.stderr.on("data", (data) => {
239240
stderr += data;
241+
this.outputChannel.appendLine(data as string);
240242
});
241243

242244
process.on("error", (err) => {

vscode-client/testcontrollermanager.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import * as vscode from "vscode";
66
import { DebugManager } from "./debugmanager";
77
import * as fs from "fs";
88

9-
import {
10-
ClientState,
11-
LanguageClientsManager,
12-
toVsCodeRange,
13-
SUPPORTED_LANGUAGES,
14-
SUPPORTED_SUITE_FILE_EXTENSIONS,
15-
} from "./languageclientsmanger";
9+
import { ClientState, LanguageClientsManager, toVsCodeRange } from "./languageclientsmanger";
1610
import { filterAsync, Mutex, sleep, truncateAndReplaceNewlines, WeakValueMap } from "./utils";
1711
import { CONFIG_SECTION } from "./config";
1812
import { Range, Diagnostic, DiagnosticSeverity } from "vscode-languageclient/node";
@@ -553,8 +547,9 @@ export class TestControllerManager {
553547
}
554548

555549
public refreshDocument(document: vscode.TextDocument): void {
556-
if (!SUPPORTED_LANGUAGES.includes(document.languageId)) return;
557-
if (!SUPPORTED_SUITE_FILE_EXTENSIONS.some((ext) => document.uri.path.toLowerCase().endsWith(ext))) return;
550+
if (!this.languageClientsManager.supportedLanguages.includes(document.languageId)) return;
551+
if (!this.languageClientsManager.fileExtensions.some((ext) => document.uri.path.toLowerCase().endsWith(`.${ext}`)))
552+
return;
558553
if (document.uri.path.toLowerCase().endsWith("__init__.robot")) return;
559554

560555
const uri_str = document.uri.toString();
@@ -712,7 +707,7 @@ export class TestControllerManager {
712707
): Promise<RobotTestItem[] | undefined> {
713708
// TODO do not use hardcoded file extensions
714709
const robotFiles = await vscode.workspace.findFiles(
715-
new vscode.RelativePattern(folder, "**/*.robot"),
710+
new vscode.RelativePattern(folder, `**/*.{${this.languageClientsManager.fileExtensions.join(",")}}`),
716711
undefined,
717712
1,
718713
token,
@@ -727,10 +722,10 @@ export class TestControllerManager {
727722

728723
for (const document of vscode.workspace.textDocuments) {
729724
if (
730-
SUPPORTED_LANGUAGES.includes(document.languageId) &&
725+
this.languageClientsManager.supportedLanguages.includes(document.languageId) &&
731726
vscode.workspace.getWorkspaceFolder(document.uri) === folder
732727
) {
733-
o[document.fileName] = document.getText();
728+
o[document.uri.toString()] = document.getText();
734729
}
735730
}
736731

@@ -785,10 +780,10 @@ export class TestControllerManager {
785780
const o: { [key: string]: string } = {};
786781
for (const document of vscode.workspace.textDocuments) {
787782
if (
788-
SUPPORTED_LANGUAGES.includes(document.languageId) &&
783+
this.languageClientsManager.supportedLanguages.includes(document.languageId) &&
789784
vscode.workspace.getWorkspaceFolder(document.uri) === folder
790785
) {
791-
o[document.fileName] = document.getText();
786+
o[document.uri.toString()] = document.getText();
792787
}
793788
}
794789

0 commit comments

Comments
 (0)