Skip to content

Commit

Permalink
Try downloading repo for project wide IntelliSense (#171686)
Browse files Browse the repository at this point in the history
* Try downloading repo for project wide IntelliSense

For #170920

* Defer preload
  • Loading branch information
mjbvz authored Jan 23, 2023
1 parent d2e4648 commit f6318f3
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 18 deletions.
46 changes: 39 additions & 7 deletions extensions/typescript-language-features/src/extension.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {

Expand All @@ -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<Api> {
const pluginManager = new PluginManager();
context.subscriptions.push(pluginManager);

Expand Down Expand Up @@ -69,6 +70,8 @@ export function activate(
context.subscriptions.push(experimentTelemetryReporter);
}

const logger = new Logger();

const lazyClientHost = createLazyClientHost(context, false, {
pluginManager,
commandManager,
Expand All @@ -79,6 +82,7 @@ export function activate(
activeJsTsEditorTracker,
serviceConfigurationProvider: new BrowserServiceConfigurationProvider(),
experimentTelemetryReporter,
logger,
}, item => {
onCompletionAccepted.fire(item);
});
Expand All @@ -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<void> {
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);
}
}
10 changes: 7 additions & 3 deletions extensions/typescript-language-features/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -68,6 +71,7 @@ export function activate(
activeJsTsEditorTracker,
serviceConfigurationProvider: new ElectronServiceConfigurationProvider(),
experimentTelemetryReporter,
logger,
}, item => {
onCompletionAccepted.fire(item);
});
Expand Down
19 changes: 13 additions & 6 deletions extensions/typescript-language-features/src/lazyClientHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -32,6 +33,7 @@ export function createLazyClientHost(
activeJsTsEditorTracker: ActiveJsTsEditorTracker;
serviceConfigurationProvider: ServiceConfigurationProvider;
experimentTelemetryReporter: IExperimentationTelemetryReporter | undefined;
logger: Logger;
},
onCompletionAccepted: (item: vscode.CompletionItem) => void,
): Lazy<TypeScriptServiceClientHost> {
Expand All @@ -53,6 +55,7 @@ export function lazilyActivateClient(
lazyClientHost: Lazy<TypeScriptServiceClientHost>,
pluginManager: PluginManager,
activeJsTsEditorTracker: ActiveJsTsEditorTracker,
onActivate: () => Promise<void> = () => Promise.resolve(),
): vscode.Disposable {
const disposables: vscode.Disposable[] = [];

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<boolean>;
}

namespace RemoteRepositories {

let remoteHub: Extension<RemoteHubApi> | undefined;

function getRemoteExtension(): Extension<RemoteHubApi> {
if (remoteHub !== undefined) {
return remoteHub;
}

remoteHub = extensions.getExtension<RemoteHubApi>('ms-vscode.remote-repositories')
?? extensions.getExtension<RemoteHubApi>('GitHub.remoteHub')
?? extensions.getExtension<RemoteHubApi>('GitHub.remoteHub-insiders');

if (remoteHub === undefined) {
throw new Error(`No Remote repository extension found.`);
}
return remoteHub;
}

export function getApi(): Thenable<RemoteHubApi> {
return getRemoteExtension().activate();
}
}

export default RemoteRepositories;
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,6 +75,7 @@ export default class TypeScriptServiceClientHost extends Disposable {
activeJsTsEditorTracker: ActiveJsTsEditorTracker;
serviceConfigurationProvider: ServiceConfigurationProvider;
experimentTelemetryReporter: IExperimentationTelemetryReporter | undefined;
logger: Logger;
},
onCompletionAccepted: (item: vscode.CompletionItem) => void,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f6318f3

Please sign in to comment.