Newer
Older
// tslint:disable
"use strict";
import { workspace, ExtensionContext } from 'vscode';
import * as vscode from 'vscode';
LanguageClient,
LanguageClientOptions,
ServerOptions,
Trace,
TransportKind
} from 'vscode-languageclient/node';
import { ModestCommands } from "./commands";
export let provider: ModestSidebarProvider;
export function activate(context: ExtensionContext) {
// The server is implemented in node
//let serverExe = "D:\\Desktop\\designproject\\modest-toolset\\Binaries\\Release\\win-x64\\Modest.LanguageServer.exe";
let serverExe = "C:\\Users\\anoni\\Desktop\\University projects\\module 11\\toolset\\Binaries\\Debug\\win-x64\\Modest.LanguageServer.exe";
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
// run: { command: serverExe, args: ['-lsp', '-d'] },
run: {
command: serverExe,
transport: TransportKind.stdio,
},
// debug: { command: serverExe, args: ['-lsp', '-d'] }
debug: {
command: serverExe,
transport: TransportKind.stdio,
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [
{
pattern: "**/*.modest",
},
// Synchronize the setting section 'languageServerExample' to the server
// configurationSection: "languageServerExample",
// fileEvents: workspace.createFileSystemWatcher("**/*.modest"),
//},
context.subscriptions.push(ModestCommands.simCommand);
context.subscriptions.push(ModestCommands.addParameters);
// Create the language client and start the client.
client = new LanguageClient(
"ModestExtension",
"Modest Extension",
serverOptions,
client.registerProposedFeatures();
let langClient = client.start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(langClient);
provider = new ModestSidebarProvider(context.extensionUri);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider(ModestSidebarProvider.viewType, provider));
export function deactivate(): Thenable<void> | undefined {
if (!client) {
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
}
class ModestSidebarProvider implements vscode.WebviewViewProvider {
public static readonly viewType = 'modest.modestSidebar';
private _view?: vscode.WebviewView;
constructor(
private readonly _extensionUri: vscode.Uri,
) { }
resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext<unknown>, token: vscode.CancellationToken): void | Thenable<void> {
this._view = webviewView;
webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,
localResourceRoots: [
this._extensionUri
]
};
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
webviewView.webview.onDidReceiveMessage(data => {
switch (data.type) {
case 'colorSelected':
{
vscode.window.activeTextEditor?.insertSnippet(new vscode.SnippetString(`#${data.value}`));
break;
}
}
});
}
/**
* sendMessage
*/
public sendMessage(message: any) {
this._view?.show(true);
this._view?.webview?.postMessage(message);
}
private _getHtmlForWebview(webview: vscode.Webview) {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'main.js'));
// Do the same for the stylesheet.
const styleResetUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'reset.css'));
const styleVSCodeUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'vscode.css'));
const styleMainUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'media', 'main.css'));
// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--
Use a content security policy to only allow loading images from https or from our extension directory,
and only allow scripts that have a specific nonce.
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${webview.cspSource}; script-src 'nonce-${nonce}';">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="${styleResetUri}" rel="stylesheet">
<link href="${styleVSCodeUri}" rel="stylesheet">
<link href="${styleMainUri}" rel="stylesheet">
<title>Modest run dialog</title>
</head>
<body>
<ul id="undefined-constants" />
<ul id="defined-constants />
<ul id="options" />
<script nonce="${nonce}" src="${scriptUri}"></script>
</body>
</html>`;
function getNonce() {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
}
}