Skip to content

Commit

Permalink
fixes regression: adding a isCheapToTokenize check before tokenizin…
Browse files Browse the repository at this point in the history
…g the line (#213674)

adding a check on how it is cheap to tokenize the lines
  • Loading branch information
aiday-mar authored May 28, 2024
1 parent 38b63e5 commit f47d99e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/vs/editor/common/tokens/lineTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,13 @@ class SliceLineTokens implements IViewLineTokens {
}
}

export function getStandardTokenTypeAtPosition(model: ITextModel, position: IPosition): StandardTokenType {
model.tokenization.forceTokenization(position.lineNumber);
const lineTokens = model.tokenization.getLineTokens(position.lineNumber);
export function getStandardTokenTypeAtPosition(model: ITextModel, position: IPosition): StandardTokenType | undefined {
const lineNumber = position.lineNumber;
if (!model.tokenization.isCheapToTokenize(lineNumber)) {
return undefined;
}
model.tokenization.forceTokenization(lineNumber);
const lineTokens = model.tokenization.getLineTokens(lineNumber);
const tokenIndex = lineTokens.findTokenIndexAtOffset(position.column - 1);
const tokenType = lineTokens.getStandardTokenType(tokenIndex);
return tokenType;
Expand Down
3 changes: 3 additions & 0 deletions src/vs/editor/contrib/indentation/common/indentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export function getReindentEditOperations(model: ITextModel, languageConfigurati
}

function doesLineStartWithString(model: ITextModel, lineNumber: number): boolean {
if (!model.tokenization.isCheapToTokenize(lineNumber)) {
return false;
}
const lineTokens = model.tokenization.getLineTokens(lineNumber);
return lineTokens.getStandardTokenType(0) === StandardTokenType.String;
}

0 comments on commit f47d99e

Please sign in to comment.