diff --git a/.eslintrc.json b/.eslintrc.json index 1995929f2..c5eb52414 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -77,7 +77,7 @@ "accessor" ], "modifiers": ["protected"], - "leadingUnderscore": "allow", + "leadingUnderscore": "forbid", "format": ["camelCase"], "filter": { "regex": "^(test_| )", diff --git a/packages/pyright-internal/src/analyzer/backgroundAnalysisProgram.ts b/packages/pyright-internal/src/analyzer/backgroundAnalysisProgram.ts index c669895f1..88c2e1d54 100644 --- a/packages/pyright-internal/src/analyzer/backgroundAnalysisProgram.ts +++ b/packages/pyright-internal/src/analyzer/backgroundAnalysisProgram.ts @@ -30,7 +30,7 @@ export class BackgroundAnalysisProgram { private _console: ConsoleInterface, private _configOptions: ConfigOptions, private _importResolver: ImportResolver, - protected _backgroundAnalysis?: BackgroundAnalysisBase, + private _backgroundAnalysis?: BackgroundAnalysisBase, private _maxAnalysisTime?: MaxAnalysisTime, private _disableChecker?: boolean, cacheManager?: CacheManager @@ -65,6 +65,10 @@ export class BackgroundAnalysisProgram { return this._backgroundAnalysis; } + set backgroundAnalysis(value: BackgroundAnalysisBase | undefined) { + this._backgroundAnalysis = value; + } + hasSourceFile(filePath: string): boolean { return !!this._program.getSourceFile(filePath); } @@ -147,7 +151,7 @@ export class BackgroundAnalysisProgram { startAnalysis(token: CancellationToken): boolean { if (this._backgroundAnalysis) { - this._backgroundAnalysis.startAnalysis(this._getIndices(), token); + this._backgroundAnalysis.startAnalysis(this.getIndices(), token); return false; } @@ -183,7 +187,7 @@ export class BackgroundAnalysisProgram { } getIndexing(filePath: string) { - return this._getIndices()?.getIndex(this._configOptions.findExecEnvironment(filePath).root); + return this.getIndices()?.getIndex(this._configOptions.findExecEnvironment(filePath).root); } async getDiagnosticsForRange(filePath: string, range: Range, token: CancellationToken): Promise { @@ -244,7 +248,7 @@ export class BackgroundAnalysisProgram { this._backgroundAnalysis?.shutdown(); } - protected _getIndices(): Indices | undefined { + protected getIndices(): Indices | undefined { return undefined; } diff --git a/packages/pyright-internal/src/analyzer/importResolver.ts b/packages/pyright-internal/src/analyzer/importResolver.ts index e9ca72485..9d3734bde 100644 --- a/packages/pyright-internal/src/analyzer/importResolver.ts +++ b/packages/pyright-internal/src/analyzer/importResolver.ts @@ -121,7 +121,7 @@ export class ImportResolver { private _stdlibModules: Set | undefined; protected cachedParentImportResults: ParentDirectoryCache; - constructor(readonly fileSystem: FileSystem, protected _configOptions: ConfigOptions, readonly host: Host) { + constructor(readonly fileSystem: FileSystem, private _configOptions: ConfigOptions, readonly host: Host) { this.cachedParentImportResults = new ParentDirectoryCache(() => this.getPythonSearchPaths([])); } @@ -145,9 +145,9 @@ export class ImportResolver { execEnv: ExecutionEnvironment, moduleDescriptor: ImportedModuleDescriptor ): ImportResult { - // Wrap internal call to _resolveImport() to prevent calling any + // Wrap internal call to resolveImportInternal() to prevent calling any // child class version of resolveImport(). - return this._resolveImport(sourceFilePath, execEnv, moduleDescriptor); + return this.resolveImportInternal(sourceFilePath, execEnv, moduleDescriptor); } getCompletionSuggestions( @@ -445,7 +445,7 @@ export class ImportResolver { // Resolves the import and returns the path if it exists, otherwise // returns undefined. - protected _resolveImport( + protected resolveImportInternal( sourceFilePath: string, execEnv: ExecutionEnvironment, moduleDescriptor: ImportedModuleDescriptor @@ -2297,7 +2297,7 @@ export class ImportResolver { .isImportFound; } - return this._resolveImport(sourceFilePath, execEnv, moduleDescriptor).isImportFound; + return this.resolveImportInternal(sourceFilePath, execEnv, moduleDescriptor).isImportFound; } private _isUniqueValidSuggestion(suggestionToAdd: string, suggestions: Map) { diff --git a/packages/pyright-internal/src/backgroundAnalysisBase.ts b/packages/pyright-internal/src/backgroundAnalysisBase.ts index 351783b51..d23d04707 100644 --- a/packages/pyright-internal/src/backgroundAnalysisBase.ts +++ b/packages/pyright-internal/src/backgroundAnalysisBase.ts @@ -287,8 +287,8 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase private _configOptions: ConfigOptions; private _program: Program; - protected _importResolver: ImportResolver; - protected _logTracker: LogTracker; + protected importResolver: ImportResolver; + protected logTracker: LogTracker; protected constructor() { super(workerData as InitializationData); @@ -298,12 +298,12 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase this.log(LogLevel.Info, `Background analysis(${threadId}) root directory: ${data.rootDirectory}`); this._configOptions = new ConfigOptions(data.rootDirectory); - this._importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost()); + this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost()); const console = this.getConsole(); - this._logTracker = new LogTracker(console, `BG(${threadId})`); + this.logTracker = new LogTracker(console, `BG(${threadId})`); - this._program = new Program(this._importResolver, this._configOptions, console, this._logTracker); + this._program = new Program(this.importResolver, this._configOptions, console, this.logTracker); // Create the extensions bound to the program for this background thread Extensions.createProgramExtensions(this._program, { @@ -391,22 +391,18 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase } case 'setImportResolver': { - this._importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost()); + this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost()); - this.program.setImportResolver(this._importResolver); + this.program.setImportResolver(this.importResolver); break; } case 'setConfigOptions': { this._configOptions = createConfigOptionsFrom(msg.data); - this._importResolver = this.createImportResolver( - this.fs, - this._configOptions, - this._importResolver.host - ); + this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.importResolver.host); this.program.setConfigOptions(this._configOptions); - this.program.setImportResolver(this._importResolver); + this.program.setImportResolver(this.importResolver); break; } @@ -425,7 +421,7 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase const { executionRoot } = msg.data; const execEnv = this._configOptions.getExecutionEnvironments().find((e) => e.root === executionRoot); if (execEnv) { - this._importResolver.ensurePartialStubPackages(execEnv); + this.importResolver.ensurePartialStubPackages(execEnv); } break; } @@ -470,7 +466,7 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase case 'invalidateAndForceReanalysis': { // Make sure the import resolver doesn't have invalid // cached entries. - this._importResolver.invalidateCache(); + this.importResolver.invalidateCache(); // Mark all files with one or more errors dirty. this.program.markAllFilesDirty(/* evenIfContentsAreSame */ true, /* indexingNeeded */ msg.data); @@ -479,12 +475,8 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase case 'restart': { // recycle import resolver - this._importResolver = this.createImportResolver( - this.fs, - this._configOptions, - this._importResolver.host - ); - this.program.setImportResolver(this._importResolver); + this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.importResolver.host); + this.program.setImportResolver(this.importResolver); break; } diff --git a/packages/pyright-internal/src/common/fullAccessHost.ts b/packages/pyright-internal/src/common/fullAccessHost.ts index 6cfabc743..a92939592 100644 --- a/packages/pyright-internal/src/common/fullAccessHost.ts +++ b/packages/pyright-internal/src/common/fullAccessHost.ts @@ -60,7 +60,7 @@ export class LimitedAccessHost extends NoAccessHost { } export class FullAccessHost extends LimitedAccessHost { - constructor(protected _fs: FileSystem) { + constructor(protected fs: FileSystem) { super(); } @@ -84,7 +84,7 @@ export class FullAccessHost extends LimitedAccessHost { override getPythonSearchPaths(pythonPath?: string, logInfo?: string[]): PythonPathResult { const importFailureInfo = logInfo ?? []; let result = this._executePythonInterpreter(pythonPath, (p) => - this._getSearchPathResultFromInterpreter(this._fs, p, importFailureInfo) + this._getSearchPathResultFromInterpreter(this.fs, p, importFailureInfo) ); if (!result) { diff --git a/packages/pyright-internal/src/common/uriParser.ts b/packages/pyright-internal/src/common/uriParser.ts index 49ebf77d7..f98509aa5 100644 --- a/packages/pyright-internal/src/common/uriParser.ts +++ b/packages/pyright-internal/src/common/uriParser.ts @@ -15,7 +15,7 @@ import { FileSystem } from './fileSystem'; import { convertUriToPath } from './pathUtils'; export class UriParser { - constructor(protected readonly _fs: FileSystem) {} + constructor(protected readonly fs: FileSystem) {} decodeTextDocumentPosition(textDocument: TextDocumentIdentifier, position: Position) { const filePath = this.decodeTextDocumentUri(textDocument.uri); @@ -23,7 +23,7 @@ export class UriParser { } decodeTextDocumentUri(uriString: string) { - return convertUriToPath(this._fs, uriString); + return convertUriToPath(this.fs, uriString); } isLocal(uri: URI | string | undefined) { diff --git a/packages/pyright-internal/src/languageServerBase.ts b/packages/pyright-internal/src/languageServerBase.ts index 4c28004eb..aa39708a5 100644 --- a/packages/pyright-internal/src/languageServerBase.ts +++ b/packages/pyright-internal/src/languageServerBase.ts @@ -293,10 +293,6 @@ namespace VSDiagnosticRank { } export abstract class LanguageServerBase implements LanguageServerInterface { - protected _defaultClientConfig: any; - protected _workspaceFactory: WorkspaceFactory; - protected _cacheManager: CacheManager; - // We support running only one "find all reference" at a time. private _pendingFindAllRefsCancellationSource: AbstractCancellationTokenSource | undefined; @@ -338,37 +334,38 @@ export abstract class LanguageServerBase implements LanguageServerInterface { completionItemResolveSupportsAdditionalTextEdits: false, }; - // File system abstraction. - protected _serviceFS: PyrightFileSystem; - - protected _uriParser: UriParser; + protected defaultClientConfig: any; + protected workspaceFactory: WorkspaceFactory; + protected cacheManager: CacheManager; + protected fs: PyrightFileSystem; + protected uriParser: UriParser; constructor( - protected _serverOptions: ServerOptions, - protected _connection: Connection, + protected serverOptions: ServerOptions, + protected connection: Connection, readonly console: ConsoleInterface, uriParserFactory = (fs: FileSystem) => new UriParser(fs) ) { // Stash the base directory into a global variable. // This must happen before fs.getModulePath(). - (global as any).__rootDirectory = _serverOptions.rootDirectory; + (global as any).__rootDirectory = serverOptions.rootDirectory; this.console.info( - `${_serverOptions.productName} language server ${ - _serverOptions.version && _serverOptions.version + ' ' + `${serverOptions.productName} language server ${ + serverOptions.version && serverOptions.version + ' ' }starting` ); - this.console.info(`Server root directory: ${_serverOptions.rootDirectory}`); + this.console.info(`Server root directory: ${serverOptions.rootDirectory}`); - this._cacheManager = new CacheManager(); + this.cacheManager = new CacheManager(); - this._serviceFS = new PyrightFileSystem(this._serverOptions.fileSystem); - this._uriParser = uriParserFactory(this._serviceFS); + this.fs = new PyrightFileSystem(this.serverOptions.fileSystem); + this.uriParser = uriParserFactory(this.fs); - this._workspaceFactory = new WorkspaceFactory( + this.workspaceFactory = new WorkspaceFactory( this.console, - this._uriParser, + this.uriParser, this.createAnalyzerServiceForWorkspace.bind(this), this.isPythonPathImmutable.bind(this), this.onWorkspaceCreated.bind(this) @@ -377,18 +374,18 @@ export abstract class LanguageServerBase implements LanguageServerInterface { // Set the working directory to a known location within // the extension directory. Otherwise the execution of // python can have unintended and surprising results. - const moduleDirectory = this._serviceFS.getModulePath(); + const moduleDirectory = this.fs.getModulePath(); if (moduleDirectory) { - this._serviceFS.chdir(moduleDirectory); + this.fs.chdir(moduleDirectory); } // Set up callbacks. - this.setupConnection(_serverOptions.supportedCommands ?? [], _serverOptions.supportedCodeActions ?? []); + this.setupConnection(serverOptions.supportedCommands ?? [], serverOptions.supportedCodeActions ?? []); this._progressReporter = new ProgressReportTracker(this.createProgressReporter()); // Listen on the connection. - this._connection.listen(); + this.connection.listen(); // Setup extensions Extensions.createLanguageServiceExtensions(this); @@ -396,7 +393,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { // Provides access to the client's window. get window(): RemoteWindow { - return this._connection.window; + return this.connection.window; } get supportAdvancedEdits(): boolean { @@ -405,7 +402,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { // Convert uri to path decodeTextDocumentUri(uriString: string): string { - return this._uriParser.decodeTextDocumentUri(uriString); + return this.uriParser.decodeTextDocumentUri(uriString); } abstract createBackgroundAnalysis(serviceId: string): BackgroundAnalysisBase | undefined; @@ -422,16 +419,16 @@ export abstract class LanguageServerBase implements LanguageServerInterface { this.console.info(`Starting service instance "${name}"`); const serviceId = getNextServiceId(name); - const service = new AnalyzerService(name, services?.fs ?? this._serviceFS, { + const service = new AnalyzerService(name, services?.fs ?? this.fs, { console: this.console, hostFactory: this.createHost.bind(this), importResolverFactory: this.createImportResolver.bind(this), backgroundAnalysis: services ? services.backgroundAnalysis : this.createBackgroundAnalysis(serviceId), - maxAnalysisTime: this._serverOptions.maxAnalysisTimeInForeground, + maxAnalysisTime: this.serverOptions.maxAnalysisTimeInForeground, backgroundAnalysisProgramFactory: this.createBackgroundAnalysisProgram.bind(this), - cancellationProvider: this._serverOptions.cancellationProvider, + cancellationProvider: this.serverOptions.cancellationProvider, libraryReanalysisTimeProvider, - cacheManager: this._cacheManager, + cacheManager: this.cacheManager, serviceId, }); @@ -440,7 +437,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { } async test_getWorkspaces() { - const workspaces = [...this._workspaceFactory.items()]; + const workspaces = [...this.workspaceFactory.items()]; for (const workspace of workspaces) { await workspace.isInitialized.promise; } @@ -449,28 +446,28 @@ export abstract class LanguageServerBase implements LanguageServerInterface { } async getWorkspaceForFile(filePath: string, pythonPath?: string): Promise { - return this._workspaceFactory.getWorkspaceForFile(filePath, pythonPath); + return this.workspaceFactory.getWorkspaceForFile(filePath, pythonPath); } async getContainingWorkspacesForFile(filePath: string): Promise { - return this._workspaceFactory.getContainingWorkspacesForFile(filePath); + return this.workspaceFactory.getContainingWorkspacesForFile(filePath); } reanalyze() { - this._workspaceFactory.items().forEach((workspace) => { + this.workspaceFactory.items().forEach((workspace) => { workspace.service.invalidateAndForceReanalysis(); }); } restart() { - this._workspaceFactory.items().forEach((workspace) => { + this.workspaceFactory.items().forEach((workspace) => { workspace.service.restart(); }); } updateSettingsForAllWorkspaces(): void { const tasks: Promise[] = []; - this._workspaceFactory.items().forEach((workspace) => { + this.workspaceFactory.items().forEach((workspace) => { // Updating settings can change workspace's file ownership. Make workspace uninitialized so that // features can wait until workspace gets new settings. // the file's ownership can also changed by `pyrightconfig.json` changes, but those are synchronous @@ -497,7 +494,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { (this.console as ConsoleWithLogLevel).level = serverSettings.logLevel ?? LogLevel.Info; // Apply the new path to the workspace (before restarting the service). - serverSettings.pythonPath = this._workspaceFactory.applyPythonPath(workspace, serverSettings.pythonPath); + serverSettings.pythonPath = this.workspaceFactory.applyPythonPath(workspace, serverSettings.pythonPath); // Then use the updated settings to restart the service. this.updateOptionsAndRestartService(workspace, serverSettings); @@ -549,11 +546,11 @@ export abstract class LanguageServerBase implements LanguageServerInterface { if (section !== undefined) { item.section = section; } - return this._connection.workspace.getConfiguration(item); + return this.connection.workspace.getConfiguration(item); } - if (this._defaultClientConfig) { - return getNestedProperty(this._defaultClientConfig, section); + if (this.defaultClientConfig) { + return getNestedProperty(this.defaultClientConfig, section); } return undefined; @@ -607,54 +604,54 @@ export abstract class LanguageServerBase implements LanguageServerInterface { protected setupConnection(supportedCommands: string[], supportedCodeActions: string[]): void { // After the server has started the client sends an initialize request. The server receives // in the passed params the rootPath of the workspace plus the client capabilities. - this._connection.onInitialize((params) => this.initialize(params, supportedCommands, supportedCodeActions)); + this.connection.onInitialize((params) => this.initialize(params, supportedCommands, supportedCodeActions)); - this._connection.onInitialized(() => this.onInitialized()); + this.connection.onInitialized(() => this.onInitialized()); - this._connection.onDidChangeConfiguration((params) => this.onDidChangeConfiguration(params)); + this.connection.onDidChangeConfiguration((params) => this.onDidChangeConfiguration(params)); - this._connection.onCodeAction((params, token) => this.executeCodeAction(params, token)); + this.connection.onCodeAction((params, token) => this.executeCodeAction(params, token)); - this._connection.onDefinition(async (params, token) => this.onDefinition(params, token)); - this._connection.onDeclaration(async (params, token) => this.onDeclaration(params, token)); - this._connection.onTypeDefinition(async (params, token) => this.onTypeDefinition(params, token)); + this.connection.onDefinition(async (params, token) => this.onDefinition(params, token)); + this.connection.onDeclaration(async (params, token) => this.onDeclaration(params, token)); + this.connection.onTypeDefinition(async (params, token) => this.onTypeDefinition(params, token)); - this._connection.onReferences(async (params, token, workDoneReporter, resultReporter) => + this.connection.onReferences(async (params, token, workDoneReporter, resultReporter) => this.onReferences(params, token, workDoneReporter, resultReporter) ); - this._connection.onDocumentSymbol(async (params, token) => this.onDocumentSymbol(params, token)); - this._connection.onWorkspaceSymbol(async (params, token, _, resultReporter) => + this.connection.onDocumentSymbol(async (params, token) => this.onDocumentSymbol(params, token)); + this.connection.onWorkspaceSymbol(async (params, token, _, resultReporter) => this.onWorkspaceSymbol(params, token, resultReporter) ); - this._connection.onHover(async (params, token) => this.onHover(params, token)); + this.connection.onHover(async (params, token) => this.onHover(params, token)); - this._connection.onDocumentHighlight(async (params, token) => this.onDocumentHighlight(params, token)); + this.connection.onDocumentHighlight(async (params, token) => this.onDocumentHighlight(params, token)); - this._connection.onSignatureHelp(async (params, token) => this.onSignatureHelp(params, token)); + this.connection.onSignatureHelp(async (params, token) => this.onSignatureHelp(params, token)); - this._connection.onCompletion((params, token) => this.onCompletion(params, token)); + this.connection.onCompletion((params, token) => this.onCompletion(params, token)); - this._connection.onCompletionResolve(async (params, token) => this.onCompletionResolve(params, token)); + this.connection.onCompletionResolve(async (params, token) => this.onCompletionResolve(params, token)); - this._connection.onPrepareRename(async (params, token) => this.onPrepareRenameRequest(params, token)); - this._connection.onRenameRequest(async (params, token) => this.onRenameRequest(params, token)); + this.connection.onPrepareRename(async (params, token) => this.onPrepareRenameRequest(params, token)); + this.connection.onRenameRequest(async (params, token) => this.onRenameRequest(params, token)); - const callHierarchy = this._connection.languages.callHierarchy; + const callHierarchy = this.connection.languages.callHierarchy; callHierarchy.onPrepare(async (params, token) => this.onPrepare(params, token)); callHierarchy.onIncomingCalls(async (params, token) => this.onIncomingCalls(params, token)); callHierarchy.onOutgoingCalls(async (params, token) => this.onOutgoingCalls(params, token)); - this._connection.onDidOpenTextDocument(async (params) => this.onDidOpenTextDocument(params)); - this._connection.onDidChangeTextDocument(async (params) => this.onDidChangeTextDocument(params)); - this._connection.onDidCloseTextDocument(async (params) => this.onDidCloseTextDocument(params)); - this._connection.onDidChangeWatchedFiles((params) => this.onDidChangeWatchedFiles(params)); + this.connection.onDidOpenTextDocument(async (params) => this.onDidOpenTextDocument(params)); + this.connection.onDidChangeTextDocument(async (params) => this.onDidChangeTextDocument(params)); + this.connection.onDidCloseTextDocument(async (params) => this.onDidCloseTextDocument(params)); + this.connection.onDidChangeWatchedFiles((params) => this.onDidChangeWatchedFiles(params)); - this._connection.onExecuteCommand(async (params, token, reporter) => + this.connection.onExecuteCommand(async (params, token, reporter) => this.onExecuteCommand(params, token, reporter) ); - this._connection.onShutdown(async (token) => this.onShutdown(token)); + this.connection.onShutdown(async (token) => this.onShutdown(token)); } protected initialize( @@ -714,7 +711,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { ); // Create a service instance for each of the workspace folders. - this._workspaceFactory.handleInitialize(params); + this.workspaceFactory.handleInitialize(params); const result: InitializeResult = { capabilities: { @@ -774,8 +771,8 @@ export abstract class LanguageServerBase implements LanguageServerInterface { return; } - this._connection.workspace.onDidChangeWorkspaceFolders((event) => { - this._workspaceFactory.handleWorkspaceFoldersChanged(event); + this.connection.workspace.onDidChangeWorkspaceFolders((event) => { + this.workspaceFactory.handleWorkspaceFoldersChanged(event); this._setupFileWatcher(); }); @@ -785,7 +782,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { protected onDidChangeConfiguration(params: DidChangeConfigurationParams) { this.console.log(`Received updated settings`); if (params?.settings) { - this._defaultClientConfig = params?.settings; + this.defaultClientConfig = params?.settings; } this.updateSettingsForAllWorkspaces(); } @@ -845,7 +842,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { ) { this.recordUserInteractionTime(); - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -885,7 +882,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { this._pendingFindAllRefsCancellationSource = source; try { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition( + const { filePath, position } = this.uriParser.decodeTextDocumentPosition( params.textDocument, params.position ); @@ -915,7 +912,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { ): Promise { this.recordUserInteractionTime(); - const filePath = this._uriParser.decodeTextDocumentUri(params.textDocument.uri); + const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -942,7 +939,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { ? (symbols) => resultReporter.report(symbols) : (symbols) => appendArray(symbolList, symbols); - for (const workspace of this._workspaceFactory.items()) { + for (const workspace of this.workspaceFactory.items()) { await workspace.isInitialized.promise; if (!workspace.disableLanguageServices && !workspace.disableWorkspaceSymbol) { workspace.service.reportSymbolsForWorkspace(params.query, reporter, token); @@ -953,7 +950,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { } protected async onHover(params: HoverParams, token: CancellationToken) { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); return workspace.service.run((program) => { @@ -962,7 +959,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { filePath, position, this.client.hoverContentFormat, - !!this._serverOptions.supportsTelemetry, + !!this.serverOptions.supportsTelemetry, token ).getHover(); }, token); @@ -972,7 +969,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { params: DocumentHighlightParams, token: CancellationToken ): Promise { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); return workspace.service.run((program) => { @@ -984,7 +981,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { params: SignatureHelpParams, token: CancellationToken ): Promise { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -1023,7 +1020,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { this._lastTriggerKind = params.context?.triggerKind; - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -1049,7 +1046,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { completions.completionList && completions.completionList.items.length > 0 && completions.memberAccessInfo.lastKnownModule && - this._serverOptions.supportsTelemetry + this.serverOptions.supportsTelemetry ) { // Just stick it on the first item. It only checks the first one completions.completionList.items[0].data = { @@ -1080,7 +1077,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { params: PrepareRenameParams, token: CancellationToken ): Promise { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -1102,7 +1099,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { params: RenameParams, token: CancellationToken ): Promise { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -1129,7 +1126,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { params: CallHierarchyPrepareParams, token: CancellationToken ): Promise { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.textDocument, params.position); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.textDocument, params.position); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -1142,7 +1139,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { } protected async onIncomingCalls(params: CallHierarchyIncomingCallsParams, token: CancellationToken) { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.item, params.item.range.start); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.item, params.item.range.start); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -1158,7 +1155,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { params: CallHierarchyOutgoingCallsParams, token: CancellationToken ): Promise { - const { filePath, position } = this._uriParser.decodeTextDocumentPosition(params.item, params.item.range.start); + const { filePath, position } = this.uriParser.decodeTextDocumentPosition(params.item, params.item.range.start); const workspace = await this.getWorkspaceForFile(filePath); if (workspace.disableLanguageServices) { @@ -1171,9 +1168,9 @@ export abstract class LanguageServerBase implements LanguageServerInterface { } protected async onDidOpenTextDocument(params: DidOpenTextDocumentParams, ipythonMode = IPythonMode.None) { - const filePath = this._uriParser.decodeTextDocumentUri(params.textDocument.uri); + const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri); - if (!this._serviceFS.addUriMap(params.textDocument.uri, filePath)) { + if (!this.fs.addUriMap(params.textDocument.uri, filePath)) { // We do not support opening 1 file with 2 different uri. return; } @@ -1188,8 +1185,8 @@ export abstract class LanguageServerBase implements LanguageServerInterface { protected async onDidChangeTextDocument(params: DidChangeTextDocumentParams, ipythonMode = IPythonMode.None) { this.recordUserInteractionTime(); - const filePath = this._uriParser.decodeTextDocumentUri(params.textDocument.uri); - if (!this._serviceFS.hasUriMapEntry(params.textDocument.uri, filePath)) { + const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri); + if (!this.fs.hasUriMapEntry(params.textDocument.uri, filePath)) { // We do not support opening 1 file with 2 different uri. return; } @@ -1202,8 +1199,8 @@ export abstract class LanguageServerBase implements LanguageServerInterface { } protected async onDidCloseTextDocument(params: DidCloseTextDocumentParams) { - const filePath = this._uriParser.decodeTextDocumentUri(params.textDocument.uri); - if (!this._serviceFS.removeUriMap(params.textDocument.uri, filePath)) { + const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri); + if (!this.fs.removeUriMap(params.textDocument.uri, filePath)) { // We do not support opening 1 file with 2 different uri. return; } @@ -1217,9 +1214,9 @@ export abstract class LanguageServerBase implements LanguageServerInterface { protected onDidChangeWatchedFiles(params: DidChangeWatchedFilesParams) { params.changes.forEach((change) => { - const filePath = this._serviceFS.realCasePath(this._uriParser.decodeTextDocumentUri(change.uri)); + const filePath = this.fs.realCasePath(this.uriParser.decodeTextDocumentUri(change.uri)); const eventType: FileWatcherEventType = change.type === 1 ? 'add' : 'change'; - this._serverOptions.fileWatcherHandler.onFileChange(eventType, filePath); + this.serverOptions.fileWatcherHandler.onFileChange(eventType, filePath); }); } @@ -1239,13 +1236,13 @@ export abstract class LanguageServerBase implements LanguageServerInterface { if (WorkspaceEdit.is(result)) { // Tell client to apply edits. // Do not await; the client isn't expecting a result. - this._connection.workspace.applyEdit({ label: `Command '${params.command}'`, edit: result }); + this.connection.workspace.applyEdit({ label: `Command '${params.command}'`, edit: result }); } if (CommandResult.is(result)) { // Tell client to apply edits. // Await so that we return after the edit is complete. - await this._connection.workspace.applyEdit({ label: result.label, edit: result.edits }); + await this.connection.workspace.applyEdit({ label: result.label, edit: result.edits }); } return result; @@ -1273,7 +1270,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { protected onShutdown(token: CancellationToken) { // Shutdown remaining workspaces. - this._workspaceFactory.clear(); + this.workspaceFactory.clear(); return Promise.resolve(); } @@ -1340,7 +1337,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { } this._sendDiagnostics(this.convertDiagnostics(fs, fileDiag)); - this._serviceFS.pendingRequest(fileDiag.filePath, fileDiag.diagnostics.length > 0); + this.fs.pendingRequest(fileDiag.filePath, fileDiag.diagnostics.length > 0); }); if (!this._progressReporter.isEnabled(results)) { @@ -1393,7 +1390,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { const libraryReanalysisTimeProvider = kinds.length === 1 && kinds[0] === WellKnownWorkspaceKinds.Regular ? () => - this._workspaceFactory.hasMultipleWorkspaces(kinds[0]) + this.workspaceFactory.hasMultipleWorkspaces(kinds[0]) ? multiWorkspaceBackOffTime : defaultBackOffTime : () => defaultBackOffTime; @@ -1405,7 +1402,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { // Tell all of the services that the user is actively // interacting with one or more editors, so they should // back off from performing any work. - this._workspaceFactory.items().forEach((workspace: { service: { recordUserInteractionTime: () => void } }) => { + this.workspaceFactory.items().forEach((workspace: { service: { recordUserInteractionTime: () => void } }) => { workspace.service.recordUserInteractionTime(); }); } @@ -1440,22 +1437,22 @@ export abstract class LanguageServerBase implements LanguageServerInterface { // Get rid of any search path under workspace root since it is already watched by // "**" above. const foldersToWatch = deduplicateFolders( - this._workspaceFactory + this.workspaceFactory .getNonDefaultWorkspaces() .map((w) => w.searchPathsToWatch.filter((p) => !p.startsWith(w.rootPath))) ); foldersToWatch.forEach((p) => { - const globPattern = isFile(this._serviceFS, p, /* treatZipDirectoryAsFile */ true) - ? { baseUri: convertPathToUri(this._serviceFS, getDirectoryPath(p)), pattern: getFileName(p) } - : { baseUri: convertPathToUri(this._serviceFS, p), pattern: '**' }; + const globPattern = isFile(this.fs, p, /* treatZipDirectoryAsFile */ true) + ? { baseUri: convertPathToUri(this.fs, getDirectoryPath(p)), pattern: getFileName(p) } + : { baseUri: convertPathToUri(this.fs, p), pattern: '**' }; watchers.push({ globPattern, kind: watchKind }); }); } // File watcher is pylance wide service. Dispose all existing file watchers and create new ones. - this._connection.client.register(DidChangeWatchedFilesNotification.type, { watchers }).then((d) => { + this.connection.client.register(DidChangeWatchedFilesNotification.type, { watchers }).then((d) => { if (this._lastFileWatcherRegistration) { this._lastFileWatcherRegistration.dispose(); } @@ -1466,7 +1463,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { private _sendDiagnostics(params: PublishDiagnosticsParams[]) { for (const param of params) { - this._connection.sendDiagnostics(param); + this.connection.sendDiagnostics(param); } } @@ -1488,10 +1485,10 @@ export abstract class LanguageServerBase implements LanguageServerInterface { // created by the LSP library. If it's the latter, we'll create a server-initiated // progress reporter. if (reporter.constructor !== nullProgressReporter.constructor) { - return { reporter: reporter, source: CancelAfter(this._serverOptions.cancellationProvider, token) }; + return { reporter: reporter, source: CancelAfter(this.serverOptions.cancellationProvider, token) }; } - const serverInitiatedReporter = await this._connection.window.createWorkDoneProgress(); + const serverInitiatedReporter = await this.connection.window.createWorkDoneProgress(); serverInitiatedReporter.begin( title, /* percentage */ undefined, @@ -1501,7 +1498,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { return { reporter: serverInitiatedReporter, - source: CancelAfter(this._serverOptions.cancellationProvider, token, serverInitiatedReporter.token), + source: CancelAfter(this.serverOptions.cancellationProvider, token, serverInitiatedReporter.token), }; } @@ -1511,7 +1508,7 @@ export abstract class LanguageServerBase implements LanguageServerInterface { diags.forEach((diag) => { const severity = convertCategoryToSeverity(diag.category); const rule = diag.getRule(); - const vsDiag = Diagnostic.create(diag.range, diag.message, severity, rule, this._serverOptions.productName); + const vsDiag = Diagnostic.create(diag.range, diag.message, severity, rule, this.serverOptions.productName); if ( diag.category === DiagnosticCategory.UnusedCode || diff --git a/packages/pyright-internal/src/languageService/definitionProvider.ts b/packages/pyright-internal/src/languageService/definitionProvider.ts index 975d9063b..1ca8adafe 100644 --- a/packages/pyright-internal/src/languageService/definitionProvider.ts +++ b/packages/pyright-internal/src/languageService/definitionProvider.ts @@ -36,16 +36,16 @@ export enum DefinitionFilter { class DefinitionProviderBase { protected constructor( - protected readonly _sourceMapper: SourceMapper, - protected readonly _evaluator: TypeEvaluator, - protected readonly _node: ParseNode | undefined, - protected readonly _offset: number, + protected readonly sourceMapper: SourceMapper, + protected readonly evaluator: TypeEvaluator, + protected readonly node: ParseNode | undefined, + protected readonly offset: number, private readonly _filter: DefinitionFilter, - protected readonly _token: CancellationToken + protected readonly token: CancellationToken ) {} getDefinitionsForNode(node: ParseNode, offset: number) { - throwIfCancellationRequested(this._token); + throwIfCancellationRequested(this.token); const definitions: DocumentRange[] = []; @@ -53,24 +53,24 @@ class DefinitionProviderBase { Extensions.getProgramExtensions(node).forEach((e) => { if (e.declarationProviderExtension) { const declarations = e.declarationProviderExtension.tryGetDeclarations( - this._evaluator, + this.evaluator, node, offset, DeclarationUseCase.Definition, - this._token + this.token ); - this._resolveDeclarations(declarations, definitions); + this.resolveDeclarations(declarations, definitions); } }); // There should be only one 'definition', so only if extensions failed should we try again. if (definitions.length === 0) { if (node.nodeType === ParseNodeType.Name) { - const declarations = this._evaluator.getDeclarationsForNameNode(node); - this._resolveDeclarations(declarations, definitions); + const declarations = this.evaluator.getDeclarationsForNameNode(node); + this.resolveDeclarations(declarations, definitions); } else if (node.nodeType === ParseNodeType.String) { - const declarations = this._evaluator.getDeclarationsForStringNode(node); - this._resolveDeclarations(declarations, definitions); + const declarations = this.evaluator.getDeclarationsForStringNode(node); + this.resolveDeclarations(declarations, definitions); } } @@ -93,10 +93,10 @@ class DefinitionProviderBase { return definitions; } - protected _resolveDeclarations(declarations: Declaration[] | undefined, definitions: DocumentRange[]) { + protected resolveDeclarations(declarations: Declaration[] | undefined, definitions: DocumentRange[]) { if (declarations) { declarations.forEach((decl) => { - let resolvedDecl = this._evaluator.resolveAliasDeclaration( + let resolvedDecl = this.evaluator.resolveAliasDeclaration( decl, /* resolveLocalNames */ true, /* allowExternallyHiddenAccess */ true @@ -126,7 +126,7 @@ class DefinitionProviderBase { if (isFunctionDeclaration(resolvedDecl)) { // Handle overloaded function case - const functionType = this._evaluator.getTypeForDeclaration(resolvedDecl)?.type; + const functionType = this.evaluator.getTypeForDeclaration(resolvedDecl)?.type; if (functionType && isOverloadedFunction(functionType)) { for (const overloadDecl of functionType.overloads .map((o) => o.details.declaration) @@ -142,13 +142,13 @@ class DefinitionProviderBase { if (isStubFile(resolvedDecl.path)) { if (resolvedDecl.type === DeclarationType.Alias) { // Add matching source module - this._sourceMapper + this.sourceMapper .findModules(resolvedDecl.path) .map((m) => getFileInfo(m)?.filePath) .filter(isDefined) .forEach((f) => _addIfUnique(definitions, _createModuleEntry(f))); } else { - const implDecls = this._sourceMapper.findDeclarations(resolvedDecl); + const implDecls = this.sourceMapper.findDeclarations(resolvedDecl); for (const implDecl of implDecls) { if (implDecl && implDecl.path) { _addIfUnique(definitions, { @@ -192,11 +192,11 @@ export class DefinitionProvider extends DefinitionProviderBase { } getDefinitions(): DocumentRange[] | undefined { - if (this._node === undefined) { + if (this.node === undefined) { return undefined; } - return this.getDefinitionsForNode(this._node, this._offset); + return this.getDefinitionsForNode(this.node, this.offset); } } @@ -213,15 +213,15 @@ export class TypeDefinitionProvider extends DefinitionProviderBase { } getDefinitions(): DocumentRange[] | undefined { - throwIfCancellationRequested(this._token); - if (this._node === undefined) { + throwIfCancellationRequested(this.token); + if (this.node === undefined) { return undefined; } const definitions: DocumentRange[] = []; - if (this._node.nodeType === ParseNodeType.Name) { - const type = this._evaluator.getType(this._node); + if (this.node.nodeType === ParseNodeType.Name) { + const type = this.evaluator.getType(this.node); if (type) { let declarations: Declaration[] = []; @@ -230,7 +230,7 @@ export class TypeDefinitionProvider extends DefinitionProviderBase { if (subtype?.category === TypeCategory.Class) { appendArray( declarations, - this._sourceMapper.findClassDeclarationsByType(this._filePath, subtype) + this.sourceMapper.findClassDeclarationsByType(this._filePath, subtype) ); } }); @@ -238,14 +238,14 @@ export class TypeDefinitionProvider extends DefinitionProviderBase { // Fall back to Go To Definition if the type can't be found (ex. Go To Type Definition // was executed on a type name) if (declarations.length === 0) { - declarations = this._evaluator.getDeclarationsForNameNode(this._node) ?? []; + declarations = this.evaluator.getDeclarationsForNameNode(this.node) ?? []; } - this._resolveDeclarations(declarations, definitions); + this.resolveDeclarations(declarations, definitions); } - } else if (this._node.nodeType === ParseNodeType.String) { - const declarations = this._evaluator.getDeclarationsForStringNode(this._node); - this._resolveDeclarations(declarations, definitions); + } else if (this.node.nodeType === ParseNodeType.String) { + const declarations = this.evaluator.getDeclarationsForStringNode(this.node); + this.resolveDeclarations(declarations, definitions); } if (definitions.length === 0) { diff --git a/packages/pyright-internal/src/pyrightFileSystem.ts b/packages/pyright-internal/src/pyrightFileSystem.ts index 936e94c83..baab66a01 100644 --- a/packages/pyright-internal/src/pyrightFileSystem.ts +++ b/packages/pyright-internal/src/pyrightFileSystem.ts @@ -66,27 +66,27 @@ export class PyrightFileSystem } override mkdirSync(path: string, options?: MkDirOptions): void { - this._realFS.mkdirSync(path, options); + this.realFS.mkdirSync(path, options); } override chdir(path: string): void { - this._realFS.chdir(path); + this.realFS.chdir(path); } override writeFileSync(path: string, data: string | Buffer, encoding: BufferEncoding | null): void { - this._realFS.writeFileSync(this._getOriginalPath(path), data, encoding); + this.realFS.writeFileSync(this.getOriginalPath(path), data, encoding); } override unlinkSync(path: string): void { - this._realFS.unlinkSync(this._getOriginalPath(path)); + this.realFS.unlinkSync(this.getOriginalPath(path)); } override createWriteStream(path: string): fs.WriteStream { - return this._realFS.createWriteStream(this._getOriginalPath(path)); + return this.realFS.createWriteStream(this.getOriginalPath(path)); } override copyFileSync(src: string, dst: string): void { - this._realFS.copyFileSync(this._getOriginalPath(src), this._getOriginalPath(dst)); + this.realFS.copyFileSync(this.getOriginalPath(src), this.getOriginalPath(dst)); } override getUri(originalPath: string): string { @@ -95,7 +95,7 @@ export class PyrightFileSystem return entry.uri; } - return this._realFS.getUri(originalPath); + return this.realFS.getUri(originalPath); } hasUriMapEntry(uriString: string, mappedPath: string): boolean { @@ -165,14 +165,14 @@ export class PyrightFileSystem for (const path of paths) { this._rootSearched.add(path); - if (!this._realFS.existsSync(path) || !isDirectory(this._realFS, path)) { + if (!this.realFS.existsSync(path) || !isDirectory(this.realFS, path)) { continue; } let dirEntries: fs.Dirent[] = []; try { - dirEntries = this._realFS.readdirEntriesSync(path); + dirEntries = this.realFS.readdirEntriesSync(path); } catch { // Leave empty set of dir entries to process. } @@ -182,13 +182,13 @@ export class PyrightFileSystem const partialStubPackagePath = combinePaths(path, entry.name); const isDirectory = !entry.isSymbolicLink() ? entry.isDirectory() - : !!tryStat(this._realFS, partialStubPackagePath)?.isDirectory(); + : !!tryStat(this.realFS, partialStubPackagePath)?.isDirectory(); if (!isDirectory || !entry.name.endsWith(stubsSuffix)) { continue; } - const pyTypedInfo = getPyTypedInfo(this._realFS, partialStubPackagePath); + const pyTypedInfo = getPyTypedInfo(this.realFS, partialStubPackagePath); if (!pyTypedInfo || !pyTypedInfo.isPartiallyTyped) { // Stub-Package is fully typed. continue; @@ -203,7 +203,7 @@ export class PyrightFileSystem for (const root of roots) { const packagePath = combinePaths(root, packageName); try { - const stat = tryStat(this._realFS, packagePath); + const stat = tryStat(this.realFS, packagePath); if (!stat?.isDirectory()) { continue; } @@ -211,7 +211,7 @@ export class PyrightFileSystem if (isBundledStub) { // If partial stub we found is from bundled stub and library installed is marked as py.typed // ignore bundled partial stub. - const packagePyTyped = getPyTypedInfo(this._realFS, packagePath); + const packagePyTyped = getPyTypedInfo(this.realFS, packagePath); if (packagePyTyped && !packagePyTyped.isPartiallyTyped) { // We have fully typed package. continue; @@ -224,7 +224,7 @@ export class PyrightFileSystem const originalPyiFile = combinePaths(partialStubPackagePath, partialStub); const mappedPyiFile = combinePaths(packagePath, partialStub); - this._recordMovedEntry(mappedPyiFile, originalPyiFile); + this.recordMovedEntry(mappedPyiFile, originalPyiFile); } } catch { // ignore @@ -235,18 +235,18 @@ export class PyrightFileSystem } override dispose(): void { - this._realFS.dispose(); + this.realFS.dispose(); } clearPartialStubs(): void { - super._clear(); + super.clear(); this._rootSearched.clear(); this._partialStubPackagePaths.clear(); } - protected override _isMovedEntry(path: string) { - return this._partialStubPackagePaths.has(path) || super._isMovedEntry(path); + protected override isMovedEntry(path: string) { + return this._partialStubPackagePaths.has(path) || super.isMovedEntry(path); } private _getRelativePathPartialStubs(path: string) { @@ -254,13 +254,13 @@ export class PyrightFileSystem const partialStubPathLength = ensureTrailingDirectorySeparator(path).length; const searchAllStubs = (path: string) => { - for (const entry of this._realFS.readdirEntriesSync(path)) { + for (const entry of this.realFS.readdirEntriesSync(path)) { const filePath = combinePaths(path, entry.name); let isDirectory = entry.isDirectory(); let isFile = entry.isFile(); if (entry.isSymbolicLink()) { - const stat = tryStat(this._realFS, filePath); + const stat = tryStat(this.realFS, filePath); if (stat) { isDirectory = stat.isDirectory(); isFile = stat.isFile(); diff --git a/packages/pyright-internal/src/readonlyAugmentedFileSystem.ts b/packages/pyright-internal/src/readonlyAugmentedFileSystem.ts index 90e934af1..af3d3ea6d 100644 --- a/packages/pyright-internal/src/readonlyAugmentedFileSystem.ts +++ b/packages/pyright-internal/src/readonlyAugmentedFileSystem.ts @@ -31,15 +31,15 @@ export class ReadOnlyAugmentedFileSystem implements FileSystem { // Mapped files per a containing folder map private readonly _folderMap = new Map(); - constructor(protected _realFS: FileSystem) {} + constructor(protected realFS: FileSystem) {} existsSync(path: string): boolean { - if (this._isMovedEntry(path)) { + if (this.isMovedEntry(path)) { // Pretend partial stub folder and its files not exist return false; } - return this._realFS.existsSync(this._getOriginalPath(path)); + return this.realFS.existsSync(this.getOriginalPath(path)); } mkdirSync(path: string, options?: MkDirOptions): void { @@ -55,14 +55,14 @@ export class ReadOnlyAugmentedFileSystem implements FileSystem { const entries: fs.Dirent[] = []; const movedEntries = this._folderMap.get(maybeDirectory); - if (!movedEntries || this._realFS.existsSync(path)) { + if (!movedEntries || this.realFS.existsSync(path)) { entries.push( - ...this._realFS.readdirEntriesSync(path).filter((item) => { + ...this.realFS.readdirEntriesSync(path).filter((item) => { // Filter out the stub package directory and any // entries that will be overwritten by stub package // virtual items. return ( - !this._isMovedEntry(combinePaths(path, item.name)) && + !this.isMovedEntry(combinePaths(path, item.name)) && !movedEntries?.some((movedEntry) => movedEntry.name === item.name) ); }) @@ -83,7 +83,7 @@ export class ReadOnlyAugmentedFileSystem implements FileSystem { readFileSync(path: string, encoding?: null): Buffer; readFileSync(path: string, encoding: BufferEncoding): string; readFileSync(path: string, encoding?: BufferEncoding | null): string | Buffer { - return this._realFS.readFileSync(this._getOriginalPath(path), encoding); + return this.realFS.readFileSync(this.getOriginalPath(path), encoding); } writeFileSync(path: string, data: string | Buffer, encoding: BufferEncoding | null): void { @@ -91,7 +91,7 @@ export class ReadOnlyAugmentedFileSystem implements FileSystem { } statSync(path: string): Stats { - return this._realFS.statSync(this._getOriginalPath(path)); + return this.realFS.statSync(this.getOriginalPath(path)); } unlinkSync(path: string): void { @@ -103,19 +103,19 @@ export class ReadOnlyAugmentedFileSystem implements FileSystem { return path; } - return this._realFS.realpathSync(path); + return this.realFS.realpathSync(path); } getModulePath(): string { - return this._realFS.getModulePath(); + return this.realFS.getModulePath(); } createFileSystemWatcher(paths: string[], listener: FileWatcherEventHandler): FileWatcher { - return this._realFS.createFileSystemWatcher(paths, listener); + return this.realFS.createFileSystemWatcher(paths, listener); } createReadStream(path: string): fs.ReadStream { - return this._realFS.createReadStream(this._getOriginalPath(path)); + return this.realFS.createReadStream(this.getOriginalPath(path)); } createWriteStream(path: string): fs.WriteStream { @@ -128,55 +128,55 @@ export class ReadOnlyAugmentedFileSystem implements FileSystem { // Async I/O readFile(path: string): Promise { - return this._realFS.readFile(this._getOriginalPath(path)); + return this.realFS.readFile(this.getOriginalPath(path)); } readFileText(path: string, encoding?: BufferEncoding): Promise { - return this._realFS.readFileText(this._getOriginalPath(path), encoding); + return this.realFS.readFileText(this.getOriginalPath(path), encoding); } // The directory returned by tmpdir must exist and be the same each time tmpdir is called. tmpdir(): string { - return this._realFS.tmpdir(); + return this.realFS.tmpdir(); } tmpfile(options?: TmpfileOptions): string { - return this._realFS.tmpfile(options); + return this.realFS.tmpfile(options); } realCasePath(path: string): string { - return this._realFS.realCasePath(path); + return this.realFS.realCasePath(path); } getUri(originalPath: string): string { - return this._realFS.getUri(originalPath); + return this.realFS.getUri(originalPath); } // See whether the file is mapped to another location. isMappedFilePath(filepath: string): boolean { - return this._entryMap.has(filepath) || this._realFS.isMappedFilePath(filepath); + return this._entryMap.has(filepath) || this.realFS.isMappedFilePath(filepath); } // Get original filepath if the given filepath is mapped. getOriginalFilePath(mappedFilePath: string) { - return this._realFS.getOriginalFilePath(this._getOriginalPath(mappedFilePath)); + return this.realFS.getOriginalFilePath(this.getOriginalPath(mappedFilePath)); } // Get mapped filepath if the given filepath is mapped. getMappedFilePath(originalFilepath: string) { - const mappedFilePath = this._realFS.getMappedFilePath(originalFilepath); + const mappedFilePath = this.realFS.getMappedFilePath(originalFilepath); return this._reverseEntryMap.get(mappedFilePath) ?? mappedFilePath; } isInZipOrEgg(path: string): boolean { - return this._realFS.isInZipOrEgg(path); + return this.realFS.isInZipOrEgg(path); } dispose(): void { - this._realFS.dispose(); + this.realFS.dispose(); } - protected _recordMovedEntry(mappedPath: string, originalPath: string, reversible = true, isFile = true) { + protected recordMovedEntry(mappedPath: string, originalPath: string, reversible = true, isFile = true) { this._entryMap.set(mappedPath, originalPath); if (reversible) { @@ -192,15 +192,15 @@ export class ReadOnlyAugmentedFileSystem implements FileSystem { } } - protected _getOriginalPath(mappedFilePath: string) { + protected getOriginalPath(mappedFilePath: string) { return this._entryMap.get(mappedFilePath) ?? mappedFilePath; } - protected _isMovedEntry(path: string) { + protected isMovedEntry(path: string) { return this._reverseEntryMap.has(path); } - protected _clear() { + protected clear() { this._entryMap.clear(); this._reverseEntryMap.clear(); this._folderMap.clear(); diff --git a/packages/pyright-internal/src/server.ts b/packages/pyright-internal/src/server.ts index 737456c8a..a3f6c9418 100644 --- a/packages/pyright-internal/src/server.ts +++ b/packages/pyright-internal/src/server.ts @@ -23,7 +23,7 @@ import { BackgroundAnalysisBase } from './backgroundAnalysisBase'; import { CommandController } from './commands/commandController'; import { getCancellationFolderName } from './common/cancellationUtils'; import { ConfigOptions, SignatureDisplayType } from './common/configOptions'; -import { ConsoleWithLogLevel, convertLogLevel, LogLevel } from './common/console'; +import { ConsoleWithLogLevel, LogLevel, convertLogLevel } from './common/console'; import { isDebugMode, isString } from './common/core'; import { expandPathVariables } from './common/envVarUtils'; import { FileBasedCancellationProvider } from './common/fileBasedCancellationUtils'; @@ -32,7 +32,7 @@ import { FullAccessHost } from './common/fullAccessHost'; import { Host } from './common/host'; import { resolvePaths } from './common/pathUtils'; import { ProgressReporter } from './common/progressReporter'; -import { createFromRealFileSystem, WorkspaceFileWatcherProvider } from './common/realFileSystem'; +import { WorkspaceFileWatcherProvider, createFromRealFileSystem } from './common/realFileSystem'; import { LanguageServerBase, ServerSettings } from './languageServerBase'; import { CodeActionProvider } from './languageService/codeActionProvider'; import { Workspace } from './workspaceFactory'; @@ -219,7 +219,7 @@ export class PyrightServer extends LanguageServerBase { } protected override createHost() { - return new FullAccessHost(this._serviceFS); + return new FullAccessHost(this.fs); } protected override createImportResolver(fs: FileSystem, options: ConfigOptions, host: Host): ImportResolver { @@ -246,7 +246,7 @@ export class PyrightServer extends LanguageServerBase { ): Promise<(Command | CodeAction)[] | undefined | null> { this.recordUserInteractionTime(); - const filePath = this._uriParser.decodeTextDocumentUri(params.textDocument.uri); + const filePath = this.uriParser.decodeTextDocumentUri(params.textDocument.uri); const workspace = await this.getWorkspaceForFile(filePath); return CodeActionProvider.getCodeActionsForPosition( workspace, @@ -266,14 +266,14 @@ export class PyrightServer extends LanguageServerBase { isEnabled: (data: AnalysisResults) => true, begin: () => { if (this.client.hasWindowProgressCapability) { - workDoneProgress = this._connection.window.createWorkDoneProgress(); + workDoneProgress = this.connection.window.createWorkDoneProgress(); workDoneProgress .then((progress) => { progress.begin(''); }) .ignoreErrors(); } else { - this._connection.sendNotification('pyright/beginProgress'); + this.connection.sendNotification('pyright/beginProgress'); } }, report: (message: string) => { @@ -284,7 +284,7 @@ export class PyrightServer extends LanguageServerBase { }) .ignoreErrors(); } else { - this._connection.sendNotification('pyright/reportProgress', message); + this.connection.sendNotification('pyright/reportProgress', message); } }, end: () => { @@ -296,7 +296,7 @@ export class PyrightServer extends LanguageServerBase { .ignoreErrors(); workDoneProgress = undefined; } else { - this._connection.sendNotification('pyright/endProgress'); + this.connection.sendNotification('pyright/endProgress'); } }, }; diff --git a/packages/pyright-internal/src/tests/harness/fourslash/testState.ts b/packages/pyright-internal/src/tests/harness/fourslash/testState.ts index c4e1ca94d..72a15b5cd 100644 --- a/packages/pyright-internal/src/tests/harness/fourslash/testState.ts +++ b/packages/pyright-internal/src/tests/harness/fourslash/testState.ts @@ -385,7 +385,7 @@ export class TestState { if (this.testData.rangesByText) { return this.testData.rangesByText; } - const result = this.createMultiMap(this.getRanges(), (r) => this._rangeText(r)); + const result = this.createMultiMap(this.getRanges(), (r) => this.rangeText(r)); this.testData.rangesByText = result; return result; @@ -394,7 +394,7 @@ export class TestState { getFilteredRanges( predicate: (m: Marker | undefined, d: T | undefined, text: string) => boolean ): Range[] { - return this.getRanges().filter((r) => predicate(r.marker, r.marker?.data as T | undefined, this._rangeText(r))); + return this.getRanges().filter((r) => predicate(r.marker, r.marker?.data as T | undefined, this.rangeText(r))); } getRangeByMarkerName(markerName: string): Range | undefined { @@ -904,7 +904,7 @@ export class TestState { } verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) { - this._verifyTextMatches(this._rangeText(this._getOnlyRange()), !!includeWhiteSpace, expectedText); + this._verifyTextMatches(this.rangeText(this._getOnlyRange()), !!includeWhiteSpace, expectedText); } async verifyCompletion( @@ -1536,7 +1536,7 @@ export class TestState { } } - protected _rangeText({ fileName, pos, end }: Range): string { + protected rangeText({ fileName, pos, end }: Range): string { return this.getFileContent(fileName).slice(pos, end); }