From f6318f31f763e44654c096abe98ceb48551f5eaa Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 23 Jan 2023 13:30:56 -0800 Subject: [PATCH] Try downloading repo for project wide IntelliSense (#171686) * Try downloading repo for project wide IntelliSense For #170920 * Defer preload --- .../src/extension.browser.ts | 46 ++++++++++++++++--- .../src/extension.ts | 10 ++-- .../src/lazyClientHost.ts | 19 +++++--- .../src/remoteRepositories.browser.ts | 42 +++++++++++++++++ .../src/typeScriptServiceClientHost.ts | 2 + .../src/typescriptServiceClient.ts | 8 +++- 6 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 extensions/typescript-language-features/src/remoteRepositories.browser.ts diff --git a/extensions/typescript-language-features/src/extension.browser.ts b/extensions/typescript-language-features/src/extension.browser.ts index 7b37e470b3e3f..57e6c2a97e8dd 100644 --- a/extensions/typescript-language-features/src/extension.browser.ts +++ b/extensions/typescript-language-features/src/extension.browser.ts @@ -3,12 +3,14 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as vscode from 'vscode'; import VsCodeTelemetryReporter from '@vscode/extension-telemetry'; +import * as vscode from 'vscode'; import { Api, getExtensionApi } from './api'; import { CommandManager } from './commands/commandManager'; import { registerBaseCommands } from './commands/index'; +import { ExperimentationTelemetryReporter, IExperimentationTelemetryReporter } from './experimentTelemetryReporter'; import { createLazyClientHost, lazilyActivateClient } from './lazyClientHost'; +import RemoteRepositories from './remoteRepositories.browser'; import { noopRequestCancellerFactory } from './tsServer/cancellation'; import { noopLogDirectoryProvider } from './tsServer/logDirectoryProvider'; import { WorkerServerProcess } from './tsServer/serverProcess.browser'; @@ -17,9 +19,10 @@ import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker'; import API from './utils/api'; import { TypeScriptServiceConfiguration } from './utils/configuration'; import { BrowserServiceConfigurationProvider } from './utils/configuration.browser'; -import { PluginManager } from './utils/plugins'; -import { ExperimentationTelemetryReporter, IExperimentationTelemetryReporter } from './experimentTelemetryReporter'; import { getPackageInfo } from './utils/packageInfo'; +import { PluginManager } from './utils/plugins'; +import { Logger } from './utils/logger'; +import { isWebAndHasSharedArrayBuffers } from './utils/platform'; class StaticVersionProvider implements ITypeScriptVersionProvider { @@ -39,9 +42,7 @@ class StaticVersionProvider implements ITypeScriptVersionProvider { readonly localVersions = []; } -export function activate( - context: vscode.ExtensionContext -): Api { +export async function activate(context: vscode.ExtensionContext): Promise { const pluginManager = new PluginManager(); context.subscriptions.push(pluginManager); @@ -69,6 +70,8 @@ export function activate( context.subscriptions.push(experimentTelemetryReporter); } + const logger = new Logger(); + const lazyClientHost = createLazyClientHost(context, false, { pluginManager, commandManager, @@ -79,6 +82,7 @@ export function activate( activeJsTsEditorTracker, serviceConfigurationProvider: new BrowserServiceConfigurationProvider(), experimentTelemetryReporter, + logger, }, item => { onCompletionAccepted.fire(item); }); @@ -91,7 +95,35 @@ export function activate( context.subscriptions.push(module.register()); }); - context.subscriptions.push(lazilyActivateClient(lazyClientHost, pluginManager, activeJsTsEditorTracker)); + context.subscriptions.push(lazilyActivateClient(lazyClientHost, pluginManager, activeJsTsEditorTracker, async () => { + await preload(logger); + })); return getExtensionApi(onCompletionAccepted.event, pluginManager); } + +async function preload(logger: Logger): Promise { + if (!isWebAndHasSharedArrayBuffers()) { + return; + } + + const workspaceUri = vscode.workspace.workspaceFolders?.[0].uri; + if (!workspaceUri || workspaceUri.scheme !== 'vscode-vfs' || workspaceUri.authority !== 'github') { + return undefined; + } + + try { + const remoteHubApi = await RemoteRepositories.getApi(); + if (remoteHubApi.loadWorkspaceContents !== undefined) { + if (await remoteHubApi.loadWorkspaceContents(workspaceUri)) { + logger.info(`Successfully loaded workspace content for repository ${workspaceUri.toString()}`); + } else { + logger.info(`Failed to load workspace content for repository ${workspaceUri.toString()}`); + } + + } + } catch (error) { + logger.info(`Loading workspace content for repository ${workspaceUri.toString()} failed: ${error instanceof Error ? error.toString() : 'Unknown reason'}`); + console.error(error); + } +} diff --git a/extensions/typescript-language-features/src/extension.ts b/extensions/typescript-language-features/src/extension.ts index 32be9c9153f50..b4072aadfd448 100644 --- a/extensions/typescript-language-features/src/extension.ts +++ b/extensions/typescript-language-features/src/extension.ts @@ -3,14 +3,14 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import VsCodeTelemetryReporter from '@vscode/extension-telemetry'; import * as fs from 'fs'; import * as vscode from 'vscode'; -import VsCodeTelemetryReporter from '@vscode/extension-telemetry'; import { Api, getExtensionApi } from './api'; import { CommandManager } from './commands/commandManager'; import { registerBaseCommands } from './commands/index'; -import { ExperimentationService } from './experimentationService'; import { ExperimentationTelemetryReporter, IExperimentationTelemetryReporter } from './experimentTelemetryReporter'; +import { ExperimentationService } from './experimentationService'; import { createLazyClientHost, lazilyActivateClient } from './lazyClientHost'; import { nodeRequestCancellerFactory } from './tsServer/cancellation.electron'; import { NodeLogDirectoryProvider } from './tsServer/logDirectoryProvider.electron'; @@ -20,9 +20,10 @@ import { JsWalkthroughState, registerJsNodeWalkthrough } from './ui/jsNodeWalkth import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker'; import { ElectronServiceConfigurationProvider } from './utils/configuration.electron'; import { onCaseInsensitiveFileSystem } from './utils/fileSystem.electron'; +import { Logger } from './utils/logger'; +import { getPackageInfo } from './utils/packageInfo'; import { PluginManager } from './utils/plugins'; import * as temp from './utils/temp.electron'; -import { getPackageInfo } from './utils/packageInfo'; export function activate( context: vscode.ExtensionContext @@ -58,6 +59,8 @@ export function activate( new ExperimentationService(experimentTelemetryReporter, id, version, context.globalState); } + const logger = new Logger(); + const lazyClientHost = createLazyClientHost(context, onCaseInsensitiveFileSystem(), { pluginManager, commandManager, @@ -68,6 +71,7 @@ export function activate( activeJsTsEditorTracker, serviceConfigurationProvider: new ElectronServiceConfigurationProvider(), experimentTelemetryReporter, + logger, }, item => { onCompletionAccepted.fire(item); }); diff --git a/extensions/typescript-language-features/src/lazyClientHost.ts b/extensions/typescript-language-features/src/lazyClientHost.ts index 377d9c09fa1c5..d815c9b52d8a2 100644 --- a/extensions/typescript-language-features/src/lazyClientHost.ts +++ b/extensions/typescript-language-features/src/lazyClientHost.ts @@ -15,7 +15,8 @@ import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker'; import { ServiceConfigurationProvider } from './utils/configuration'; import * as fileSchemes from './utils/fileSchemes'; import { standardLanguageDescriptions } from './utils/languageDescription'; -import { lazy, Lazy } from './utils/lazy'; +import { Lazy, lazy } from './utils/lazy'; +import { Logger } from './utils/logger'; import ManagedFileContextManager from './utils/managedFileContext'; import { PluginManager } from './utils/plugins'; @@ -32,6 +33,7 @@ export function createLazyClientHost( activeJsTsEditorTracker: ActiveJsTsEditorTracker; serviceConfigurationProvider: ServiceConfigurationProvider; experimentTelemetryReporter: IExperimentationTelemetryReporter | undefined; + logger: Logger; }, onCompletionAccepted: (item: vscode.CompletionItem) => void, ): Lazy { @@ -53,6 +55,7 @@ export function lazilyActivateClient( lazyClientHost: Lazy, pluginManager: PluginManager, activeJsTsEditorTracker: ActiveJsTsEditorTracker, + onActivate: () => Promise = () => Promise.resolve(), ): vscode.Disposable { const disposables: vscode.Disposable[] = []; @@ -65,12 +68,16 @@ export function lazilyActivateClient( const maybeActivate = (textDocument: vscode.TextDocument): boolean => { if (!hasActivated && isSupportedDocument(supportedLanguage, textDocument)) { hasActivated = true; - // Force activation - void lazyClientHost.value; - disposables.push(new ManagedFileContextManager(activeJsTsEditorTracker, resource => { - return lazyClientHost.value.serviceClient.toPath(resource); - })); + onActivate().then(() => { + // Force activation + void lazyClientHost.value; + + disposables.push(new ManagedFileContextManager(activeJsTsEditorTracker, resource => { + return lazyClientHost.value.serviceClient.toPath(resource); + })); + }); + return true; } return false; diff --git a/extensions/typescript-language-features/src/remoteRepositories.browser.ts b/extensions/typescript-language-features/src/remoteRepositories.browser.ts new file mode 100644 index 0000000000000..b9b0d05a22cd3 --- /dev/null +++ b/extensions/typescript-language-features/src/remoteRepositories.browser.ts @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Extension, extensions, Uri } from 'vscode'; + +export interface RemoteHubApi { + getProviderUri(uri: Uri): Uri; + getProviderRootUri(uri: Uri): Uri; + + getVirtualUri(uri: Uri): Uri; + getVirtualWorkspaceUri(uri: Uri): Uri | undefined; + + loadWorkspaceContents?(workspaceUri: Uri): Promise; +} + +namespace RemoteRepositories { + + let remoteHub: Extension | undefined; + + function getRemoteExtension(): Extension { + if (remoteHub !== undefined) { + return remoteHub; + } + + remoteHub = extensions.getExtension('ms-vscode.remote-repositories') + ?? extensions.getExtension('GitHub.remoteHub') + ?? extensions.getExtension('GitHub.remoteHub-insiders'); + + if (remoteHub === undefined) { + throw new Error(`No Remote repository extension found.`); + } + return remoteHub; + } + + export function getApi(): Thenable { + return getRemoteExtension().activate(); + } +} + +export default RemoteRepositories; diff --git a/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts b/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts index 6c2168a380c42..d89bb33290eb6 100644 --- a/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts +++ b/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts @@ -31,6 +31,7 @@ import * as errorCodes from './utils/errorCodes'; import { DiagnosticLanguage, LanguageDescription } from './utils/languageDescription'; import * as LargeProjectStatus from './utils/largeProjectStatus'; import { LogLevelMonitor } from './utils/logLevelMonitor'; +import { Logger } from './utils/logger'; import { PluginManager } from './utils/plugins'; import * as typeConverters from './utils/typeConverters'; import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus'; @@ -74,6 +75,7 @@ export default class TypeScriptServiceClientHost extends Disposable { activeJsTsEditorTracker: ActiveJsTsEditorTracker; serviceConfigurationProvider: ServiceConfigurationProvider; experimentTelemetryReporter: IExperimentationTelemetryReporter | undefined; + logger: Logger; }, onCompletionAccepted: (item: vscode.CompletionItem) => void, ) { diff --git a/extensions/typescript-language-features/src/typescriptServiceClient.ts b/extensions/typescript-language-features/src/typescriptServiceClient.ts index a88a852619b54..3a3a7266ac5b5 100644 --- a/extensions/typescript-language-features/src/typescriptServiceClient.ts +++ b/extensions/typescript-language-features/src/typescriptServiceClient.ts @@ -104,8 +104,8 @@ export default class TypeScriptServiceClient extends Disposable implements IType private readonly pluginPathsProvider: TypeScriptPluginPathsProvider; private readonly _versionManager: TypeScriptVersionManager; - private readonly logger = new Logger(); - private readonly tracer = new Tracer(this.logger); + private readonly logger: Logger; + private readonly tracer: Tracer; private readonly typescriptServerSpawner: TypeScriptServerSpawner; private serverState: ServerState.State = ServerState.None; @@ -137,11 +137,15 @@ export default class TypeScriptServiceClient extends Disposable implements IType processFactory: TsServerProcessFactory; serviceConfigurationProvider: ServiceConfigurationProvider; experimentTelemetryReporter: IExperimentationTelemetryReporter | undefined; + logger: Logger; }, allModeIds: readonly string[] ) { super(); + this.logger = services.logger; + this.tracer = new Tracer(this.logger); + this.workspaceState = context.workspaceState; this.pluginManager = services.pluginManager;