Skip to content

Commit c03e8c3

Browse files
committed
Eliminated restriction that prevented the analysis of text files that don't end in ".py" or ".pyi".
1 parent 2deb236 commit c03e8c3

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

packages/pyright-internal/src/analyzer/program.ts

-6
Original file line numberDiff line numberDiff line change
@@ -2069,12 +2069,6 @@ export class Program {
20692069
private _addToSourceFileListAndMap(fileInfo: SourceFileInfo) {
20702070
const filePath = normalizePathCase(this._fs, fileInfo.sourceFile.getFilePath());
20712071

2072-
// All source files should be ".pyi" or ".py" files.
2073-
const fileExtension = getFileExtension(filePath).toLowerCase();
2074-
if (fileExtension !== '.py' && fileExtension !== '.pyi') {
2075-
fail(`${filePath} is not a source file`);
2076-
}
2077-
20782072
// We should never add a file with the same path twice.
20792073
assert(!this._sourceFileMap.has(filePath));
20802074

packages/pyright-internal/src/languageServerBase.ts

+8-27
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import {
7474
FileWatcherEventHandler,
7575
FileWatcherEventType,
7676
} from './common/fileSystem';
77-
import { containsPath, convertPathToUri, convertUriToPath, getFileExtension } from './common/pathUtils';
77+
import { containsPath, convertPathToUri, convertUriToPath } from './common/pathUtils';
7878
import { ProgressReporter, ProgressReportTracker } from './common/progressReporter';
7979
import { convertWorkspaceEdits } from './common/textEditUtils';
8080
import { DocumentRange, Position } from './common/textRange';
@@ -776,35 +776,25 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
776776
this._connection.onDidOpenTextDocument(async (params) => {
777777
const filePath = convertUriToPath(params.textDocument.uri);
778778
const workspace = await this.getWorkspaceForFile(filePath);
779-
if (this._isSupportedSourceFileType(filePath)) {
780-
workspace.serviceInstance.setFileOpened(
781-
filePath,
782-
params.textDocument.version,
783-
params.textDocument.text
784-
);
785-
}
779+
workspace.serviceInstance.setFileOpened(filePath, params.textDocument.version, params.textDocument.text);
786780
});
787781

788782
this._connection.onDidChangeTextDocument(async (params) => {
789783
this.recordUserInteractionTime();
790784

791785
const filePath = convertUriToPath(params.textDocument.uri);
792786
const workspace = await this.getWorkspaceForFile(filePath);
793-
if (this._isSupportedSourceFileType(filePath)) {
794-
workspace.serviceInstance.updateOpenFileContents(
795-
filePath,
796-
params.textDocument.version,
797-
params.contentChanges
798-
);
799-
}
787+
workspace.serviceInstance.updateOpenFileContents(
788+
filePath,
789+
params.textDocument.version,
790+
params.contentChanges
791+
);
800792
});
801793

802794
this._connection.onDidCloseTextDocument(async (params) => {
803795
const filePath = convertUriToPath(params.textDocument.uri);
804796
const workspace = await this.getWorkspaceForFile(filePath);
805-
if (this._isSupportedSourceFileType(filePath)) {
806-
workspace.serviceInstance.setFileClosed(filePath);
807-
}
797+
workspace.serviceInstance.setFileClosed(filePath);
808798
});
809799

810800
this._connection.onDidChangeWatchedFiles((params) => {
@@ -1131,15 +1121,6 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
11311121
}
11321122
}
11331123

1134-
private _isSupportedSourceFileType(filePath: string) {
1135-
// The language server assumes that all source files are either ".py"
1136-
// or ".pyi" files. We don't want to attempt to parse other files
1137-
// (like binaries, etc.). And we need to know whether to use normal
1138-
// or stub semantics.
1139-
const extension = getFileExtension(filePath).toLowerCase();
1140-
return extension === '.py' || extension === '.pyi';
1141-
}
1142-
11431124
private _getCompatibleMarkupKind(clientSupportedFormats: MarkupKind[] | undefined) {
11441125
const serverSupportedFormats = [MarkupKind.PlainText, MarkupKind.Markdown];
11451126

0 commit comments

Comments
 (0)