Skip to content

Commit 321b6bf

Browse files
authored
Removed some circular module dependencies. (#10485)
1 parent b249d11 commit 321b6bf

14 files changed

Lines changed: 53 additions & 47 deletions

File tree

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
} from '../parser/parseNodes';
4747
import { OperatorTypeNameMap, ParseNodeTypeNameMap } from '../parser/parseNodeUtils';
4848
import { ParseFileResults } from '../parser/parser';
49-
import { TokenizerOutput } from '../parser/tokenizer';
49+
import { Tokenizer, TokenizerOutput } from '../parser/tokenizer';
5050
import { KeywordType, OperatorType, StringToken, StringTokenFlags, Token, TokenType } from '../parser/tokenizerTypes';
5151
import { getScope } from './analyzerNodeInfo';
5252
import { ParseTreeWalker, getChildNodes } from './parseTreeWalker';
@@ -1864,7 +1864,7 @@ export function getTokenIndexAtLeft(
18641864
continue;
18651865
}
18661866

1867-
if (!includeWhitespace && isWhitespace(token)) {
1867+
if (!includeWhitespace && Tokenizer.isWhitespace(token)) {
18681868
continue;
18691869
}
18701870

@@ -1919,10 +1919,6 @@ export function getTokenAfter(tokens: TextRangeCollection<Token>, position: numb
19191919
return tokens.getItemAt(index);
19201920
}
19211921

1922-
export function isWhitespace(token: Token) {
1923-
return token.type === TokenType.NewLine || token.type === TokenType.Indent || token.type === TokenType.Dedent;
1924-
}
1925-
19261922
export function getTokenAtIndex(tokens: TextRangeCollection<Token>, index: number) {
19271923
if (index < 0) {
19281924
return undefined;
@@ -2382,7 +2378,7 @@ export function getFullStatementRange(
23822378

23832379
export function isBlankLine(tokenizerOutput: TokenizerOutput, text: string, line: number) {
23842380
const span = tokenizerOutput.lines.getItemAt(line);
2385-
return containsOnlyWhitespace(text, span);
2381+
return containsOnlyWhitespace(text, span.start, TextRange.getEnd(span));
23862382
}
23872383

23882384
export function isUnannotatedFunction(node: FunctionNode) {
@@ -2700,7 +2696,7 @@ export function getPreviousNonWhitespaceToken(tokens: TextRangeCollection<Token>
27002696

27012697
while (tokenIndex >= 0) {
27022698
const token = tokens.getItemAt(tokenIndex);
2703-
if (!isWhitespace(token)) {
2699+
if (!Tokenizer.isWhitespace(token)) {
27042700
return token;
27052701
}
27062702

@@ -2711,7 +2707,7 @@ export function getPreviousNonWhitespaceToken(tokens: TextRangeCollection<Token>
27112707
}
27122708

27132709
export function getNextNonWhitespaceToken(tokens: TextRangeCollection<Token>, offset: number): Token | undefined {
2714-
return getNextMatchingToken(tokens, offset, (token) => !isWhitespace(token));
2710+
return getNextMatchingToken(tokens, offset, (token) => !Tokenizer.isWhitespace(token));
27152711
}
27162712

27172713
export function getNextMatchingToken(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ export class SourceFile {
677677
configOptions,
678678
this._uri,
679679
fileContents!,
680-
this._ipythonMode,
680+
this._ipythonMode !== IPythonMode.None,
681681
diagSink
682682
);
683683

@@ -1448,15 +1448,15 @@ export class SourceFile {
14481448
configOptions: ConfigOptions,
14491449
fileUri: Uri,
14501450
fileContents: string,
1451-
ipythonMode: IPythonMode,
1451+
useNotebookMode: boolean,
14521452
diagSink: DiagnosticSink
14531453
): ParseFileResults {
14541454
// Use the configuration options to determine the environment zin which
14551455
// this source file will be executed.
14561456
const execEnvironment = configOptions.findExecEnvironment(fileUri);
14571457

14581458
const parseOptions = new ParseOptions();
1459-
parseOptions.ipythonMode = ipythonMode;
1459+
parseOptions.useNotebookMode = useNotebookMode;
14601460
if (fileUri.pathEndsWith('pyi')) {
14611461
parseOptions.isStubFile = true;
14621462
}

packages/pyright-internal/src/common/core.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* Various helpers that don't have a dependency on other code files.
77
*/
88

9-
import { TextRange } from './textRange';
10-
119
export const enum Comparison {
1210
LessThan = -1,
1311
EqualTo = 0,
@@ -179,9 +177,9 @@ export function getEnumNames<T>(enumType: T) {
179177
return result;
180178
}
181179

182-
export function containsOnlyWhitespace(text: string, span?: TextRange) {
183-
if (span) {
184-
text = text.substring(span.start, TextRange.getEnd(span));
180+
export function containsOnlyWhitespace(text: string, start?: number, end?: number) {
181+
if (start !== undefined) {
182+
text = text.substring(start, end);
185183
}
186184

187185
return /^\s*$/.test(text);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* docRange.ts
3+
* Copyright (c) Microsoft Corporation.
4+
* Licensed under the MIT license.
5+
*
6+
* Specifies the range of text within a document.
7+
*/
8+
9+
import { Range } from './textRange';
10+
import { Uri } from './uri/uri';
11+
12+
export interface DocumentRange {
13+
uri: Uri;
14+
range: Range;
15+
}

packages/pyright-internal/src/common/textRange.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* Specifies the range of text within a larger string.
88
*/
99

10-
import { Uri } from './uri/uri';
11-
1210
export interface TextRange {
1311
readonly start: number;
1412
readonly length: number;
@@ -132,11 +130,6 @@ export namespace Range {
132130
}
133131

134132
// Represents a range within a particular document.
135-
export interface DocumentRange {
136-
uri: Uri;
137-
range: Range;
138-
}
139-
140133
export function comparePositions(a: Position, b: Position) {
141134
if (a.line < b.line) {
142135
return -1;

packages/pyright-internal/src/languageServerBase.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { ConsoleInterface, ConsoleWithLogLevel, LogLevel } from './common/consol
9494
import { Diagnostic as AnalyzerDiagnostic, DiagnosticCategory } from './common/diagnostic';
9595
import { DiagnosticRule } from './common/diagnosticRules';
9696
import { FileDiagnostics } from './common/diagnosticSink';
97+
import { DocumentRange } from './common/docRange';
9798
import { FileSystem, ReadOnlyFileSystem } from './common/fileSystem';
9899
import { FileWatcherEventType } from './common/fileWatcher';
99100
import { Host } from './common/host';
@@ -107,7 +108,7 @@ import { fromLSPAny, isNullProgressReporter } from './common/lspUtils';
107108
import { ProgressReportTracker, ProgressReporter } from './common/progressReporter';
108109
import { ServiceKeys } from './common/serviceKeys';
109110
import { ServiceProvider } from './common/serviceProvider';
110-
import { DocumentRange, Position, Range } from './common/textRange';
111+
import { Position, Range } from './common/textRange';
111112
import { Uri } from './common/uri/uri';
112113
import { convertUriToLspUriString } from './common/uri/uriUtils';
113114
import { AnalyzerServiceExecutor } from './languageService/analyzerServiceExecutor';

packages/pyright-internal/src/languageService/definitionProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import { OverloadedType, TypeCategory, isOverloaded } from '../analyzer/types';
2828
import { throwIfCancellationRequested } from '../common/cancellationUtils';
2929
import { appendArray } from '../common/collectionUtils';
3030
import { isDefined } from '../common/core';
31+
import { DocumentRange } from '../common/docRange';
3132
import { ProgramView } from '../common/extensibility';
3233
import { convertOffsetsToRange, convertPositionToOffset } from '../common/positionUtils';
3334
import { ServiceKeys } from '../common/serviceKeys';
3435
import { ServiceProvider } from '../common/serviceProvider';
35-
import { DocumentRange, Position, rangesAreEqual } from '../common/textRange';
36+
import { Position, rangesAreEqual } from '../common/textRange';
3637
import { Uri } from '../common/uri/uri';
3738
import { ParseNode, ParseNodeType } from '../parser/parseNodes';
3839
import { ParseFileResults } from '../parser/parser';

packages/pyright-internal/src/languageService/navigationUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* Helper functions for navigating files.
77
*/
88
import { Location } from 'vscode-languageserver-types';
9+
import { DocumentRange } from '../common/docRange';
910
import { ReadOnlyFileSystem } from '../common/fileSystem';
10-
import { DocumentRange } from '../common/textRange';
1111
import { Uri } from '../common/uri/uri';
1212
import { convertUriToLspUriString } from '../common/uri/uriUtils';
1313

packages/pyright-internal/src/languageService/referencesProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import { throwIfCancellationRequested } from '../common/cancellationUtils';
2222
import { appendArray } from '../common/collectionUtils';
2323
import { isDefined } from '../common/core';
2424
import { assertNever } from '../common/debug';
25+
import { DocumentRange } from '../common/docRange';
2526
import { ProgramView, ReferenceUseCase, SymbolUsageProvider } from '../common/extensibility';
2627
import { ReadOnlyFileSystem } from '../common/fileSystem';
2728
import { convertOffsetToPosition, convertPositionToOffset } from '../common/positionUtils';
2829
import { ServiceKeys } from '../common/serviceKeys';
29-
import { DocumentRange, Position, Range, TextRange, doesRangeContain } from '../common/textRange';
30+
import { Position, Range, TextRange, doesRangeContain } from '../common/textRange';
3031
import { Uri } from '../common/uri/uri';
3132
import { NameNode, ParseNode, ParseNodeType } from '../parser/parseNodes';
3233
import { ParseFileResults } from '../parser/parser';

packages/pyright-internal/src/parser/parser.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* into an abstract syntax tree (AST).
1212
*/
1313

14-
import { IPythonMode } from '../analyzer/sourceFile';
1514
import { appendArray } from '../common/collectionUtils';
1615
import { assert } from '../common/debug';
1716
import { Diagnostic, DiagnosticAddendum } from '../common/diagnostic';
@@ -166,15 +165,15 @@ export class ParseOptions {
166165
pythonVersion: PythonVersion;
167166
reportInvalidStringEscapeSequence: boolean;
168167
skipFunctionAndClassBody: boolean;
169-
ipythonMode: IPythonMode;
168+
useNotebookMode: boolean;
170169
reportErrorsForParsedStringContents: boolean;
171170

172171
constructor() {
173172
this.isStubFile = false;
174173
this.pythonVersion = latestStablePythonVersion;
175174
this.reportInvalidStringEscapeSequence = false;
176175
this.skipFunctionAndClassBody = false;
177-
this.ipythonMode = IPythonMode.None;
176+
this.useNotebookMode = false;
178177
this.reportErrorsForParsedStringContents = false;
179178
}
180179
}
@@ -399,7 +398,7 @@ export class Parser {
399398
textOffset,
400399
textLength,
401400
initialParenDepth,
402-
this._parseOptions.ipythonMode
401+
this._parseOptions.useNotebookMode
403402
);
404403
this._tokenIndex = 0;
405404
}

0 commit comments

Comments
 (0)