mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
Merge branch 'main' into reverthover
This commit is contained in:
@@ -9,19 +9,20 @@ import * as vscode from 'vscode';
|
||||
import { Api, getExtensionApi } from './api';
|
||||
import { CommandManager } from './commands/commandManager';
|
||||
import { registerBaseCommands } from './commands/index';
|
||||
import { ElectronServiceConfigurationProvider } from './configuration/configuration.electron';
|
||||
import { ExperimentationTelemetryReporter, IExperimentationTelemetryReporter } from './experimentTelemetryReporter';
|
||||
import { ExperimentationService } from './experimentationService';
|
||||
import { createLazyClientHost, lazilyActivateClient } from './lazyClientHost';
|
||||
import { Logger } from './logging/logger';
|
||||
import { nodeRequestCancellerFactory } from './tsServer/cancellation.electron';
|
||||
import { NodeLogDirectoryProvider } from './tsServer/logDirectoryProvider.electron';
|
||||
import { PluginManager } from './tsServer/plugins';
|
||||
import { ElectronServiceProcessFactory } from './tsServer/serverProcess.electron';
|
||||
import { DiskTypeScriptVersionProvider } from './tsServer/versionProvider.electron';
|
||||
import { ActiveJsTsEditorTracker } from './ui/activeJsTsEditorTracker';
|
||||
import { ElectronServiceConfigurationProvider } from './configuration/configuration.electron';
|
||||
import { onCaseInsensitiveFileSystem } from './utils/fs.electron';
|
||||
import { Logger } from './logging/logger';
|
||||
import { Lazy } from './utils/lazy';
|
||||
import { getPackageInfo } from './utils/packageInfo';
|
||||
import { PluginManager } from './tsServer/plugins';
|
||||
import * as temp from './utils/temp.electron';
|
||||
|
||||
export function activate(
|
||||
@@ -75,7 +76,7 @@ export function activate(
|
||||
registerBaseCommands(commandManager, lazyClientHost, pluginManager, activeJsTsEditorTracker);
|
||||
|
||||
import('./task/taskProvider').then(module => {
|
||||
context.subscriptions.push(module.register(lazyClientHost.map(x => x.serviceClient)));
|
||||
context.subscriptions.push(module.register(new Lazy(() => lazyClientHost.value.serviceClient)));
|
||||
});
|
||||
|
||||
import('./languageFeatures/tsconfig').then(module => {
|
||||
|
||||
@@ -15,6 +15,20 @@ import FileConfigurationManager from './fileConfigurationManager';
|
||||
import { conditionalRegistration, requireGlobalConfiguration, requireMinVersion, requireSomeCapability } from './util/dependentRegistration';
|
||||
|
||||
class CopyMetadata {
|
||||
|
||||
static parse(data: string): CopyMetadata | undefined {
|
||||
try {
|
||||
|
||||
const parsedData = JSON.parse(data);
|
||||
const resource = vscode.Uri.parse(parsedData.resource);
|
||||
const ranges = parsedData.ranges.map((range: any) => new vscode.Range(range.start, range.end));
|
||||
const copyOperation = parsedData.copyOperation ? Promise.resolve(parsedData.copyOperation) : undefined;
|
||||
return new CopyMetadata(resource, ranges, copyOperation);
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
constructor(
|
||||
public readonly resource: vscode.Uri,
|
||||
public readonly ranges: readonly vscode.Range[],
|
||||
@@ -213,7 +227,15 @@ class DocumentPasteProvider implements vscode.DocumentPasteEditProvider<TsPasteE
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return metadata instanceof CopyMetadata ? metadata : undefined;
|
||||
if (metadata instanceof CopyMetadata) {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
if (typeof metadata === 'string') {
|
||||
return CopyMetadata.parse(metadata);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private isEnabled(document: vscode.TextDocument) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import ManagedFileContextManager from './ui/managedFileContext';
|
||||
import { ServiceConfigurationProvider } from './configuration/configuration';
|
||||
import * as fileSchemes from './configuration/fileSchemes';
|
||||
import { standardLanguageDescriptions, isJsConfigOrTsConfigFileName } from './configuration/languageDescription';
|
||||
import { Lazy, lazy } from './utils/lazy';
|
||||
import { Lazy } from './utils/lazy';
|
||||
import { Logger } from './logging/logger';
|
||||
import { PluginManager } from './tsServer/plugins';
|
||||
|
||||
@@ -37,7 +37,7 @@ export function createLazyClientHost(
|
||||
},
|
||||
onCompletionAccepted: (item: vscode.CompletionItem) => void,
|
||||
): Lazy<TypeScriptServiceClientHost> {
|
||||
return lazy(() => {
|
||||
return new Lazy(() => {
|
||||
const clientHost = new TypeScriptServiceClientHost(
|
||||
standardLanguageDescriptions,
|
||||
context,
|
||||
|
||||
@@ -191,7 +191,20 @@ class SyncedBuffer {
|
||||
}
|
||||
|
||||
private getProjectRootPath(resource: vscode.Uri): string | undefined {
|
||||
const workspaceRoot = this.client.getWorkspaceRootForResource(resource);
|
||||
let workspaceRoot = this.client.getWorkspaceRootForResource(resource);
|
||||
|
||||
// If we didn't find a real workspace, we still want to try sending along a workspace folder
|
||||
// to prevent TS from loading projects from outside of any workspace.
|
||||
// Just pick the highest level one on the same FS even though the file is outside of it
|
||||
if (!workspaceRoot && vscode.workspace.workspaceFolders) {
|
||||
for (const root of Array.from(vscode.workspace.workspaceFolders).sort((a, b) => a.uri.path.length - b.uri.path.length)) {
|
||||
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
|
||||
workspaceRoot = root.uri;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (workspaceRoot) {
|
||||
const tsRoot = this.client.toTsFilePath(workspaceRoot);
|
||||
return tsRoot?.startsWith(inMemoryResourcePrefix) ? undefined : tsRoot;
|
||||
|
||||
@@ -25,7 +25,11 @@ export class TypeScriptServerError extends Error {
|
||||
public readonly serverStack: string | undefined,
|
||||
private readonly sanitizedStack: string | undefined
|
||||
) {
|
||||
super(`<${serverId}> TypeScript Server Error (${version.displayName})\n${serverMessage}\n${serverStack}`);
|
||||
super([
|
||||
`<${serverId}> TypeScript Server Error (${version.displayName})`,
|
||||
serverMessage,
|
||||
serverStack
|
||||
].filter(Boolean).join('\n'));
|
||||
}
|
||||
|
||||
public get serverErrorText() { return this.response.message; }
|
||||
|
||||
@@ -836,9 +836,10 @@ export default class TypeScriptServiceClient extends Disposable implements IType
|
||||
}
|
||||
}
|
||||
|
||||
for (const root of roots.sort((a, b) => a.uri.fsPath.length - b.uri.fsPath.length)) {
|
||||
// Find the highest level workspace folder that contains the file
|
||||
for (const root of roots.sort((a, b) => a.uri.path.length - b.uri.path.length)) {
|
||||
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
|
||||
if (resource.fsPath.startsWith(root.uri.fsPath + path.sep)) {
|
||||
if (resource.path.startsWith(root.uri.path + '/')) {
|
||||
return root.uri;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,37 +3,45 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export interface Lazy<T> {
|
||||
value: T;
|
||||
hasValue: boolean;
|
||||
map<R>(f: (x: T) => R): Lazy<R>;
|
||||
}
|
||||
export class Lazy<T> {
|
||||
|
||||
class LazyValue<T> implements Lazy<T> {
|
||||
private _hasValue: boolean = false;
|
||||
private _didRun: boolean = false;
|
||||
private _value?: T;
|
||||
private _error: Error | undefined;
|
||||
|
||||
constructor(
|
||||
private readonly _getValue: () => T
|
||||
private readonly executor: () => T,
|
||||
) { }
|
||||
|
||||
/**
|
||||
* True if the lazy value has been resolved.
|
||||
*/
|
||||
get hasValue() { return this._didRun; }
|
||||
|
||||
/**
|
||||
* Get the wrapped value.
|
||||
*
|
||||
* This will force evaluation of the lazy value if it has not been resolved yet. Lazy values are only
|
||||
* resolved once. `getValue` will re-throw exceptions that are hit while resolving the value
|
||||
*/
|
||||
get value(): T {
|
||||
if (!this._hasValue) {
|
||||
this._hasValue = true;
|
||||
this._value = this._getValue();
|
||||
if (!this._didRun) {
|
||||
try {
|
||||
this._value = this.executor();
|
||||
} catch (err) {
|
||||
this._error = err;
|
||||
} finally {
|
||||
this._didRun = true;
|
||||
}
|
||||
}
|
||||
if (this._error) {
|
||||
throw this._error;
|
||||
}
|
||||
return this._value!;
|
||||
}
|
||||
|
||||
get hasValue(): boolean {
|
||||
return this._hasValue;
|
||||
}
|
||||
|
||||
public map<R>(f: (x: T) => R): Lazy<R> {
|
||||
return new LazyValue(() => f(this.value));
|
||||
}
|
||||
/**
|
||||
* Get the wrapped value without forcing evaluation.
|
||||
*/
|
||||
get rawValue(): T | undefined { return this._value; }
|
||||
}
|
||||
|
||||
export function lazy<T>(getValue: () => T): Lazy<T> {
|
||||
return new LazyValue<T>(getValue);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { lazy } from './lazy';
|
||||
import { Lazy } from './lazy';
|
||||
|
||||
function makeRandomHexString(length: number): string {
|
||||
const chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
||||
@@ -18,12 +18,12 @@ function makeRandomHexString(length: number): string {
|
||||
return result;
|
||||
}
|
||||
|
||||
const rootTempDir = lazy(() => {
|
||||
const rootTempDir = new Lazy(() => {
|
||||
const filename = `vscode-typescript${process.platform !== 'win32' && process.getuid ? process.getuid() : ''}`;
|
||||
return path.join(os.tmpdir(), filename);
|
||||
});
|
||||
|
||||
export const instanceTempDir = lazy(() => {
|
||||
export const instanceTempDir = new Lazy(() => {
|
||||
const dir = path.join(rootTempDir.value, makeRandomHexString(20));
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
return dir;
|
||||
|
||||
Reference in New Issue
Block a user