Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
"outFiles": ["${workspaceFolder}/out/**/*", "!${workspaceFolder}/**/node_modules**/*"],
"preLaunchTask": "Compile"
},
{
"name": "Run Web Extension",
"type": "pwa-extensionHost",
"debugWebWorkerHost": true,
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionDevelopmentKind=web"
],
"outFiles": [
"${workspaceFolder}/out/client-web/**/*.js"
],
"preLaunchTask": "npm: compile-web"
},
{
"name": "Python: Current File",
"type": "python",
Expand Down
45 changes: 45 additions & 0 deletions build/webpack/webpack.extension.web.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

const path = require('path');
const constants = require('../constants');

const root = path.join(__dirname, '..', '..');

const config = {
mode: 'production',
target: 'web',
entry: {
extension: path.join(root, './src/client/extension.web.ts'),
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
configFile: "tsconfig.extension.web.json"
}
},
],
}
]
},
resolve: {
extensions: ['.ts', '.js', '.json']
},
externals: ['vscode'],
output: {
filename: '[name].js',
path: path.resolve(constants.ExtensionRootDir, 'out', 'client-web'),
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../../[resource-path]',
},
};

exports.default = config;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"workspaceContains:app.py"
],
"main": "./out/client/extension",
"browser": "./out/client-web/extension",
"contributes": {
"breakpoints": [
{
Expand Down Expand Up @@ -2075,7 +2076,9 @@
"addExtensionPackDependencies": "gulp addExtensionPackDependencies",
"updateBuildNumber": "gulp updateBuildNumber",
"verifyBundle": "gulp verifyBundle",
"webpack": "webpack"
"webpack": "webpack",
"compile-web": "webpack --config ./build/webpack/webpack.extension.web.config.js",
"watch-web": "webpack --watch --config ./build/webpack/webpack.extension.web.config.js"
},
"dependencies": {
"arch": "^2.1.0",
Expand Down
62 changes: 62 additions & 0 deletions src/client/extension.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as vscode from 'vscode';
import type { LanguageClientOptions } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/browser';
import { PYLANCE_EXTENSION_ID } from './common/constants';

declare const Worker: {
new(stringUrl: string): any;
};

const pylancePath = 'dist/browser.server.js'

export async function activate(context: vscode.ExtensionContext): Promise<void> {
const pylanceExtension = vscode.extensions.getExtension(PYLANCE_EXTENSION_ID);
if (!pylanceExtension) {
throw new Error('Could not find Pylance extension');
}

await pylanceExtension.activate();

const serverMain = vscode.Uri.joinPath(pylanceExtension.extensionUri, pylancePath);
try {
const worker = new Worker(serverMain.toString());

const clientOptions: LanguageClientOptions = {
// Register the server for python source files.
documentSelector: [
{
scheme: 'file',
language: 'python',
},
],
synchronize: {
// Synchronize the setting section to the server.
configurationSection: ['python', 'pyright'],
},
// TODO: replace cancellation strategy with SharedArrayBuffer (shared worker memory)
// connectionOptions: { cancellationStrategy: cancellationStrategy },
};

const languageClient = new LanguageClient('python', 'Pylance', clientOptions, worker);
const disposable = languageClient.start();

context.subscriptions.push(disposable);

languageClient.onTelemetry((eventInfo) => {
console.log(`onTelemetry EventName: ${eventInfo.EventName}`);

for (const [prop, value] of Object.entries(eventInfo.Properties)) {
console.log(` Property: ${prop} : ${value}`);
}

for (const [measure, value] of Object.entries(eventInfo.Measurements)) {
console.log(` Measurement: ${measure} : ${value}`);
}
});
} catch (e) {
console.log(e);
}
}
6 changes: 6 additions & 0 deletions tsconfig.extension.web.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.extension.json",
"files": [
"./src/client/extension.web.ts"
]
}