Skip to content

Commit

Permalink
Disable VS Code file watching for yarn pnp (microsoft#213238)
Browse files Browse the repository at this point in the history
Disable VS Code file watching on yarn pnp
  • Loading branch information
mjbvz authored and andremmsilva committed May 26, 2024
1 parent 4dd6c93 commit 52a4242
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
4 changes: 4 additions & 0 deletions extensions/typescript-language-features/src/tsServer/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ export class API {
public lt(other: API): boolean {
return !this.gte(other);
}

public isYarnPnp(): boolean {
return this.fullVersionString.includes('-sdk');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ export class TypeScriptServerSpawner {

args.push('--noGetErrOnBackgroundUpdate');

if (apiVersion.gte(API.v544) && configuration.useVsCodeWatcher) {
if (
apiVersion.gte(API.v544)
&& configuration.useVsCodeWatcher
&& !apiVersion.isYarnPnp() // Disable for yarn pnp as it currently breaks with the VS Code watcher
) {
args.push('--canUseWatchEvents');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@

import * as path from 'path';
import * as vscode from 'vscode';
import { ServiceConfigurationProvider, SyntaxServerConfiguration, TsServerLogLevel, TypeScriptServiceConfiguration, areServiceConfigurationsEqual } from './configuration/configuration';
import * as fileSchemes from './configuration/fileSchemes';
import { Schemes } from './configuration/schemes';
import { IExperimentationTelemetryReporter } from './experimentTelemetryReporter';
import { DiagnosticKind, DiagnosticsManager } from './languageFeatures/diagnostics';
import * as Proto from './tsServer/protocol/protocol';
import { EventName } from './tsServer/protocol/protocol.const';
import { Logger } from './logging/logger';
import { TelemetryProperties, TelemetryReporter, VSCodeTelemetryReporter } from './logging/telemetry';
import Tracer from './logging/tracer';
import { ProjectType, inferredProjectCompilerOptions } from './tsconfig';
import { API } from './tsServer/api';
import BufferSyncSupport from './tsServer/bufferSyncSupport';
import { OngoingRequestCancellerFactory } from './tsServer/cancellation';
import { ILogDirectoryProvider } from './tsServer/logDirectoryProvider';
import { NodeVersionManager } from './tsServer/nodeManager';
import { TypeScriptPluginPathsProvider } from './tsServer/pluginPathsProvider';
import { PluginManager, TypeScriptServerPlugin } from './tsServer/plugins';
import * as Proto from './tsServer/protocol/protocol';
import { EventName } from './tsServer/protocol/protocol.const';
import { ITypeScriptServer, TsServerLog, TsServerProcessFactory, TypeScriptServerExitEvent } from './tsServer/server';
import { TypeScriptServerError } from './tsServer/serverError';
import { TypeScriptServerSpawner } from './tsServer/spawner';
import { TypeScriptVersionManager } from './tsServer/versionManager';
import { ITypeScriptVersionProvider, TypeScriptVersion } from './tsServer/versionProvider';
import { ClientCapabilities, ClientCapability, ExecConfig, ITypeScriptServiceClient, ServerResponse, TypeScriptRequests } from './typescriptService';
import { ServiceConfigurationProvider, SyntaxServerConfiguration, TsServerLogLevel, TypeScriptServiceConfiguration, areServiceConfigurationsEqual } from './configuration/configuration';
import { Disposable, DisposableStore, disposeAll } from './utils/dispose';
import * as fileSchemes from './configuration/fileSchemes';
import { Logger } from './logging/logger';
import { isWeb, isWebAndHasSharedArrayBuffers } from './utils/platform';
import { PluginManager, TypeScriptServerPlugin } from './tsServer/plugins';
import { TelemetryProperties, TelemetryReporter, VSCodeTelemetryReporter } from './logging/telemetry';
import Tracer from './logging/tracer';
import { ProjectType, inferredProjectCompilerOptions } from './tsconfig';
import { Schemes } from './configuration/schemes';
import { NodeVersionManager } from './tsServer/nodeManager';


export interface TsDiagnostics {
Expand Down Expand Up @@ -463,7 +463,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}
*/
this.logTelemetry('tsserver.error');
this.serviceExited(false);
this.serviceExited(false, apiVersion);
});

handle.onExit((data: TypeScriptServerExitEvent) => {
Expand All @@ -484,7 +484,6 @@ export default class TypeScriptServiceClient extends Disposable implements IType
*/
this.logTelemetry('tsserver.exitWithCode', { code: code ?? undefined, signal: signal ?? undefined });


if (this.token !== mytoken) {
// this is coming from an old process
return;
Expand All @@ -493,7 +492,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
if (handle.tsServerLog?.type === 'file') {
this.info(`TSServer log file: ${handle.tsServerLog.uri.fsPath}`);
}
this.serviceExited(!this.isRestarting);
this.serviceExited(!this.isRestarting, apiVersion);
this.isRestarting = false;
});

Expand Down Expand Up @@ -612,7 +611,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
};
}

private serviceExited(restart: boolean): void {
private serviceExited(restart: boolean, tsVersion: API): void {
this.resetWatchers();
this.loadingIndicator.reset();

Expand Down Expand Up @@ -686,25 +685,42 @@ export default class TypeScriptServiceClient extends Disposable implements IType
this._isPromptingAfterCrash = true;
}

prompt?.then(item => {
prompt?.then(async item => {
this._isPromptingAfterCrash = false;

if (item === reportIssueItem) {

const minModernTsVersion = this.versionProvider.bundledVersion.apiVersion;

if (
// Don't allow reporting issues using the PnP patched version of TS Server
if (tsVersion.isYarnPnp()) {
const reportIssue: vscode.MessageItem = {
title: vscode.l10n.t("Report issue against Yarn PnP"),
};
const response = await vscode.window.showWarningMessage(
vscode.l10n.t("Please report an issue against Yarn PnP"),
{
modal: true,
detail: vscode.l10n.t("The workspace is using a version of the TypeScript Server that has been patched by Yarn PnP. This patching is a common source of bugs."),
},
reportIssue);

if (response === reportIssue) {
vscode.env.openExternal(vscode.Uri.parse('https://github.com/yarnpkg/berry/issues'));
}
}
// Don't allow reporting issues with old TS versions
else if (
minModernTsVersion &&
previousState.type === ServerState.Type.Errored &&
previousState.error instanceof TypeScriptServerError &&
previousState.error.version.apiVersion?.lt(minModernTsVersion)
tsVersion.lt(minModernTsVersion)
) {
vscode.window.showWarningMessage(
vscode.l10n.t("Please update your TypeScript version"),
{
modal: true,
detail: vscode.l10n.t(
"The workspace is using an old version of TypeScript ({0}).\n\nBefore reporting an issue, please update the workspace to use TypeScript {1} or newer to make sure the bug has not already been fixed.",
previousState.error.version.apiVersion.displayName,
tsVersion.displayName,
minModernTsVersion.displayName),
});
} else {
Expand Down

0 comments on commit 52a4242

Please sign in to comment.