-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVSCode.txt
87 lines (72 loc) · 3.1 KB
/
VSCode.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Install Node.js, available in $PATH
npm install -g yo generator-code
yo code
/// https://code.visualstudio.com/docs/extensions/developing-extensions
This is what happens when pressing F5:
1) .vscode/launch.json instructs to first run a task named npm.
2) .vscode/tasks.json defines the task npm as a shell command to npm run compile.
3) package.json defines the script compile as tsc -watch -p ./
4) This eventually invokes the TypeScript compiler included in node_modules, which generates out/extension.js and out/extension.js.map.
5) Once the TypeScript compilation task is finished, the code --extensionDevelopmentPath=${workspaceFolder} process is spawned.
6) The second instance of VS Code is launched in a special Extension Host mode and it searches for an extension at ${workspaceFolder}.
/// https://code.visualstudio.com/docs/extensionAPI/patterns-and-principles
Visual Studio Code will not install your extension's dependencies when a user installs it, so you must npm install before publishing. The extension's publishing package will contain all of its dependencies within. You can run vsce ls to list all the files that vsce will include in the package.
////
let clientOptions: LanguageClientOptions = {
outputChannelName: 'XYZ Language Server',
};
//
// Create a connection for the server. The connection uses
// stdin / stdout for message passing
let connection: IConnection = createConnection(process.stdin, process.stdout);
connection.console.log(`Console test.`);
////
let filePath = vscode.Uri.file(path.join(context.extensionPath, 'index.html')).toString(); //error
let filePath = join(__dirname, 'index.html');
panel.webview.html = fs.readFileSync(filePath, 'utf8');
//
vscode.workspace.openTextDocument(filePath).then((textDoc) => {
const txt = textDoc.getText();
});
//
vscode.workspace.openTextDocument().then(doc => vscode.window.showTextDocument(doc))
///
const editor = vscode.window.activeTextEditor;
editor.viewColumn
////
vscode.window.showOpenDialog({
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: true,
filters: {
["Text files"]: ["txt"],
["All files"]: ["*"],
["Some File"]: ["(*.sf)|*.sf|All Files (*.*)|*.*"]
}
}).then(uris => {
if (!uris || !uris[0]) { return; }
console.log(`uris: ${uris[0].fsPath}`);
});
/// export api
export function activate(context: vscode.ExtensionContext) {
let api = {
sum(a, b) {
return a + b;
},
mul(a, b) {
return a * b;
}
};
// 'export' public api-surface
return api;
}
And another extension can then retrieve and use that API via a getExtension() call:
let mathExt = extensions.getExtension('genius.math');
let importedApi = mathExt.exports;
console.log(importedApi.mul(42, 1));
///
// fs.writeFile(`${__dirname}/../index_raw.html`, content, (err: Error) => {
// if (err) {
// vscode.window.showErrorMessage("Cannot save index_raw: " + err);
// }
// });