Skip to content

Commit 7035176

Browse files
committed
Pass cancellable token around
1 parent 127db20 commit 7035176

29 files changed

+369
-290
lines changed

cfmleditor-0.6.15.vsix

5.41 MB
Binary file not shown.

dist/web/cfmlMain.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web/cfmlMain.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cfmleditor",
33
"displayName": "CFML Editor",
44
"description": "CFML Language Editor",
5-
"version": "0.6.14",
5+
"version": "0.6.15",
66
"preview": true,
77
"author": "cfmleditor",
88
"publisher": "cfmleditor",

src/cfmlMain.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export function activate(context: ExtensionContext): void {
134134

135135
context.subscriptions.push(commands.registerCommand("cfml.refreshGlobalDefinitionCache", refreshGlobalDefinitionCache));
136136
context.subscriptions.push(commands.registerCommand("cfml.refreshWorkspaceDefinitionCache", refreshWorkspaceDefinitionCache));
137-
context.subscriptions.push(commands.registerTextEditorCommand("cfml.toggleLineComment", toggleComment(CommentType.Line)));
138-
context.subscriptions.push(commands.registerTextEditorCommand("cfml.toggleBlockComment", toggleComment(CommentType.Block)));
137+
context.subscriptions.push(commands.registerTextEditorCommand("cfml.toggleLineComment", toggleComment(CommentType.Line, null)));
138+
context.subscriptions.push(commands.registerTextEditorCommand("cfml.toggleBlockComment", toggleComment(CommentType.Block, null)));
139139
context.subscriptions.push(commands.registerTextEditorCommand("cfml.openActiveApplicationFile", showApplicationDocument));
140140
context.subscriptions.push(commands.registerTextEditorCommand("cfml.goToMatchingTag", goToMatchingTag));
141141
context.subscriptions.push(commands.registerTextEditorCommand("cfml.openCfDocs", CFDocsService.openCfDocsForCurrentWord));
@@ -160,13 +160,13 @@ export function activate(context: ExtensionContext): void {
160160
return;
161161
}
162162

163-
if (isCfcFile(document)) {
163+
if (isCfcFile(document, null)) {
164164
const cfmlCompletionSettings: WorkspaceConfiguration = workspace.getConfiguration("cfml.suggest", document.uri);
165165
const replaceComments = cfmlCompletionSettings.get<boolean>("replaceComments", true);
166-
cachedEntity.cacheComponentFromDocument(document, false, replaceComments);
166+
cachedEntity.cacheComponentFromDocument(document, false, replaceComments, null);
167167
} else if (Utils.basename(Uri.parse(document.fileName)) === "Application.cfm") {
168-
const documentStateContext: DocumentStateContext = getDocumentStateContext(document, false, true);
169-
const thisApplicationVariables: Variable[] = await parseVariableAssignments(documentStateContext, documentStateContext.docIsScript);
168+
const documentStateContext: DocumentStateContext = getDocumentStateContext(document, false, true, null);
169+
const thisApplicationVariables: Variable[] = await parseVariableAssignments(documentStateContext, documentStateContext.docIsScript, null, null);
170170
const thisApplicationFilteredVariables: Variable[] = thisApplicationVariables.filter((variable: Variable) => {
171171
return [Scope.Application, Scope.Session, Scope.Request].includes(variable.scope);
172172
});
@@ -183,7 +183,7 @@ export function activate(context: ExtensionContext): void {
183183
workspace.openTextDocument(componentUri).then((document: TextDocument) => {
184184
const cfmlCompletionSettings: WorkspaceConfiguration = workspace.getConfiguration("cfml.suggest", document.uri);
185185
const replaceComments = cfmlCompletionSettings.get<boolean>("replaceComments", true);
186-
cachedEntity.cacheComponentFromDocument(document, false, replaceComments);
186+
cachedEntity.cacheComponentFromDocument(document, false, replaceComments, null);
187187
});
188188
});
189189
componentWatcher.onDidDelete((componentUri: Uri) => {
@@ -208,8 +208,8 @@ export function activate(context: ExtensionContext): void {
208208
}
209209

210210
workspace.openTextDocument(applicationUri).then(async (document: TextDocument) => {
211-
const documentStateContext: DocumentStateContext = getDocumentStateContext(document, false, true);
212-
const thisApplicationVariables: Variable[] = await parseVariableAssignments(documentStateContext, documentStateContext.docIsScript);
211+
const documentStateContext: DocumentStateContext = getDocumentStateContext(document, false, true, null);
212+
const thisApplicationVariables: Variable[] = await parseVariableAssignments(documentStateContext, documentStateContext.docIsScript, null, null);
213213
const thisApplicationFilteredVariables: Variable[] = thisApplicationVariables.filter((variable: Variable) => {
214214
return [Scope.Application, Scope.Session, Scope.Request].includes(variable.scope);
215215
});

src/entities/catch.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CompletionEntry } from "../features/completionItemProvider";
22
import { DocumentStateContext } from "../utils/documentUtil";
3-
import { TextDocument, Range } from "vscode";
3+
import { TextDocument, Range, CancellationToken } from "vscode";
44
import { getClosingPosition, getCfScriptRanges } from "../utils/contextUtil";
55
import { parseTags, Tag } from "./tag";
66

@@ -99,9 +99,10 @@ export interface CatchInfo {
9999
* @param documentStateContext The context information for a TextDocument in which to parse the CFScript functions
100100
* @param isScript Whether this document or range is defined entirely in CFScript
101101
* @param docRange Range within which to check
102+
* @param _token
102103
* @returns
103104
*/
104-
export function parseCatches(documentStateContext: DocumentStateContext, isScript: boolean, docRange?: Range): CatchInfo[] {
105+
export function parseCatches(documentStateContext: DocumentStateContext, isScript: boolean, docRange: Range, _token: CancellationToken): CatchInfo[] {
105106
let catchInfoArr: CatchInfo[] = [];
106107
const document: TextDocument = documentStateContext.document;
107108
let textOffset: number = 0;
@@ -120,7 +121,7 @@ export function parseCatches(documentStateContext: DocumentStateContext, isScrip
120121
const catchVariable = scriptCatchMatch[2];
121122

122123
const catchBodyStartOffset = textOffset + scriptCatchMatch.index + scriptCatchMatch[0].length;
123-
const catchBodyEndPosition = getClosingPosition(documentStateContext, catchBodyStartOffset, "}");
124+
const catchBodyEndPosition = getClosingPosition(documentStateContext, catchBodyStartOffset, "}", _token);
124125

125126
const catchBodyRange: Range = new Range(
126127
document.positionAt(catchBodyStartOffset),
@@ -137,7 +138,7 @@ export function parseCatches(documentStateContext: DocumentStateContext, isScrip
137138
}
138139
} else {
139140
const tagName: string = "cfcatch";
140-
const tags: Tag[] = parseTags(documentStateContext, tagName, docRange);
141+
const tags: Tag[] = parseTags(documentStateContext, tagName, docRange, _token);
141142

142143
tags.forEach((tag: Tag) => {
143144
if (tag.bodyRange === undefined) {
@@ -165,9 +166,9 @@ export function parseCatches(documentStateContext: DocumentStateContext, isScrip
165166
});
166167

167168
// Check cfscript sections
168-
const cfScriptRanges: Range[] = getCfScriptRanges(document, docRange);
169+
const cfScriptRanges: Range[] = getCfScriptRanges(document, docRange, _token);
169170
cfScriptRanges.forEach((range: Range) => {
170-
const cfscriptCatches: CatchInfo[] = parseCatches(documentStateContext, true, range);
171+
const cfscriptCatches: CatchInfo[] = parseCatches(documentStateContext, true, range, _token);
171172

172173
catchInfoArr = catchInfoArr.concat(cfscriptCatches);
173174
});

src/entities/component.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { Position, Range, TextDocument, Uri } from "vscode";
2+
import { CancellationToken, Position, Range, TextDocument, Uri } from "vscode";
33
import * as cachedEntities from "../features/cachedEntities";
44
import { getComponent, hasComponent } from "../features/cachedEntities";
55
import { MySet } from "../utils/collections";
@@ -159,23 +159,25 @@ export interface ComponentsByName {
159159
/**
160160
* Determines whether the given document is a script-based component
161161
* @param document The document to check
162+
* @param _token
162163
* @returns
163164
*/
164-
export function isScriptComponent(document: TextDocument): boolean {
165+
export function isScriptComponent(document: TextDocument, _token: CancellationToken): boolean {
165166
const componentTagMatch: RegExpExecArray = COMPONENT_TAG_PATTERN.exec(document.getText());
166167
if (componentTagMatch) {
167168
return false;
168169
}
169170

170-
return isCfcFile(document);
171+
return isCfcFile(document, _token);
171172
}
172173

173174
/**
174175
* Parses a component document and returns an object conforming to the Component interface
175176
* @param documentStateContext The context information for a TextDocument to be parsed
177+
* @param _token
176178
* @returns
177179
*/
178-
export async function parseComponent(documentStateContext: DocumentStateContext): Promise<Component | undefined> {
180+
export async function parseComponent(documentStateContext: DocumentStateContext, _token: CancellationToken): Promise<Component | undefined> {
179181
const document: TextDocument = documentStateContext.document;
180182
const documentText: string = document.getText();
181183
const componentIsScript: boolean = documentStateContext.docIsScript;
@@ -348,8 +350,8 @@ export async function parseComponent(documentStateContext: DocumentStateContext)
348350

349351
documentStateContext.component = component;
350352
const componentFunctions = new ComponentFunctions();
351-
let userFunctions: UserFunction[] = parseScriptFunctions(documentStateContext);
352-
userFunctions = userFunctions.concat(parseTagFunctions(documentStateContext));
353+
let userFunctions: UserFunction[] = parseScriptFunctions(documentStateContext, _token);
354+
userFunctions = userFunctions.concat(parseTagFunctions(documentStateContext, _token));
353355
let earliestFunctionRangeStart: Position = document.positionAt(documentText.length);
354356
userFunctions.forEach((compFun: UserFunction) => {
355357
if (compFun.location.range.start.isBefore(earliestFunctionRangeStart)) {
@@ -382,7 +384,7 @@ export async function parseComponent(documentStateContext: DocumentStateContext)
382384

383385
// Only check before first function definition
384386
const componentDefinitionRange = new Range(document.positionAt(componentMatch.index + head.length), earliestFunctionRangeStart);
385-
component.variables = await parseVariableAssignments(documentStateContext, componentIsScript, componentDefinitionRange);
387+
component.variables = await parseVariableAssignments(documentStateContext, componentIsScript, componentDefinitionRange, _token);
386388

387389
// TODO: Get imports
388390

@@ -537,9 +539,10 @@ export function getApplicationUri(baseUri: Uri): Uri | undefined {
537539
/**
538540
* Finds the applicable Server file for the given file URI
539541
* @param baseUri The URI from which the Server file will be searched
542+
* @param _token
540543
* @returns
541544
*/
542-
export function getServerUri(baseUri: Uri): Uri | undefined {
545+
export function getServerUri(baseUri: Uri, _token: CancellationToken): Uri | undefined {
543546
let componentUri: Uri;
544547

545548
const fileName = "Server.cfc";
@@ -548,7 +551,7 @@ export function getServerUri(baseUri: Uri): Uri | undefined {
548551
if (rootPath) {
549552
const rootUri: Uri = Uri.file(rootPath);
550553

551-
if (hasComponent(rootUri)) {
554+
if (hasComponent(rootUri, _token)) {
552555
componentUri = rootUri;
553556
}
554557
}
@@ -562,16 +565,17 @@ export function getServerUri(baseUri: Uri): Uri | undefined {
562565
* Checks whether `checkComponent` is a subcomponent or equal to `baseComponent`
563566
* @param checkComponent The candidate subcomponent
564567
* @param baseComponent The candidate base component
568+
* @param _token
565569
* @returns
566570
*/
567-
export function isSubcomponentOrEqual(checkComponent: Component, baseComponent: Component): boolean {
571+
export function isSubcomponentOrEqual(checkComponent: Component, baseComponent: Component, _token: CancellationToken): boolean {
568572
while (checkComponent) {
569573
if (checkComponent.uri.toString() === baseComponent.uri.toString()) {
570574
return true;
571575
}
572576

573577
if (checkComponent.extends) {
574-
checkComponent = getComponent(checkComponent.extends);
578+
checkComponent = getComponent(checkComponent.extends, _token);
575579
} else {
576580
checkComponent = undefined;
577581
}
@@ -584,11 +588,12 @@ export function isSubcomponentOrEqual(checkComponent: Component, baseComponent:
584588
* Checks whether `checkComponent` is a subcomponent of `baseComponent`
585589
* @param checkComponent The candidate subcomponent
586590
* @param baseComponent The candidate base component
591+
* @param _token
587592
* @returns
588593
*/
589-
export function isSubcomponent(checkComponent: Component, baseComponent: Component): boolean {
594+
export function isSubcomponent(checkComponent: Component, baseComponent: Component, _token: CancellationToken): boolean {
590595
if (checkComponent.extends) {
591-
checkComponent = getComponent(checkComponent.extends);
596+
checkComponent = getComponent(checkComponent.extends, _token);
592597
} else {
593598
return false;
594599
}
@@ -599,7 +604,7 @@ export function isSubcomponent(checkComponent: Component, baseComponent: Compone
599604
}
600605

601606
if (checkComponent.extends) {
602-
checkComponent = getComponent(checkComponent.extends);
607+
checkComponent = getComponent(checkComponent.extends, _token);
603608
} else {
604609
checkComponent = undefined;
605610
}

src/entities/function.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DataType } from "./dataType";
22
import { Signature, constructSignatureLabelParamsPart, constructSignatureLabelParamsPrefix } from "./signature";
33
import { UserFunction } from "./userFunction";
44
import { DocumentStateContext } from "../utils/documentUtil";
5-
import { Range, TextDocument, Position } from "vscode";
5+
import { Range, TextDocument, Position, CancellationToken } from "vscode";
66
import { getNextCharacterPosition } from "../utils/contextUtil";
77
import { Utils } from "vscode-uri";
88

@@ -76,16 +76,17 @@ export function getReturnTypeString(func: Function): string {
7676
* @param documentStateContext The context information for the TextDocument containing function arguments
7777
* @param argsRange The full range for a set of arguments
7878
* @param separatorChar The character that separates function arguments
79+
* @param _token
7980
* @returns
8081
*/
81-
export function getScriptFunctionArgRanges(documentStateContext: DocumentStateContext, argsRange: Range, separatorChar: string = ","): Range[] {
82+
export function getScriptFunctionArgRanges(documentStateContext: DocumentStateContext, argsRange: Range, separatorChar: string = ",", _token: CancellationToken): Range[] {
8283
const argRanges: Range[] = [];
8384
const document: TextDocument = documentStateContext.document;
8485
const argsEndOffset: number = document.offsetAt(argsRange.end);
8586

8687
let argStartPosition = argsRange.start;
8788
while (argStartPosition.isBeforeOrEqual(argsRange.end)) {
88-
const argSeparatorPos: Position = getNextCharacterPosition(documentStateContext, document.offsetAt(argStartPosition), argsEndOffset, separatorChar, false);
89+
const argSeparatorPos: Position = getNextCharacterPosition(documentStateContext, document.offsetAt(argStartPosition), argsEndOffset, separatorChar, false, _token);
8990
const argRange: Range = new Range(argStartPosition, argSeparatorPos);
9091
argRanges.push(argRange);
9192
argStartPosition = argSeparatorPos.translate(0, 1);

src/entities/tag.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Position, Range, Selection, TextDocument, TextEditor, Uri, WorkspaceConfiguration, window, workspace } from "vscode";
1+
import { CancellationToken, Position, Range, Selection, TextDocument, TextEditor, TextEditorEdit, Uri, WorkspaceConfiguration, window, workspace } from "vscode";
22
import { getGlobalTag } from "../features/cachedEntities";
33
import { StringContext, isStringDelimiter } from "../utils/contextUtil";
44
import { DocumentPositionStateContext, DocumentStateContext, getDocumentPositionStateContext } from "../utils/documentUtil";
@@ -596,9 +596,10 @@ export function getNonClosingCfmlTags(): string[] {
596596
* @param documentStateContext The context information for the TextDocument to check
597597
* @param tagName The name of the tag to capture
598598
* @param range Range within which to check
599+
* @param _token
599600
* @returns
600601
*/
601-
export function parseTags(documentStateContext: DocumentStateContext, tagName: string, range?: Range): Tag[] {
602+
export function parseTags(documentStateContext: DocumentStateContext, tagName: string, range: Range, _token: CancellationToken): Tag[] {
602603
const tags: Tag[] = [];
603604
const document: TextDocument = documentStateContext.document;
604605
let textOffset: number = 0;
@@ -653,9 +654,10 @@ export function parseTags(documentStateContext: DocumentStateContext, tagName: s
653654
* @param tagName The name of the tag to capture
654655
* @param isScript Whether this document or range is defined entirely in CFScript
655656
* @param range Range within which to check
657+
* @param _token
656658
* @returns
657659
*/
658-
export function parseStartTags(documentStateContext: DocumentStateContext, tagName: string, isScript: boolean, range?: Range): StartTag[] {
660+
export function parseStartTags(documentStateContext: DocumentStateContext, tagName: string, isScript: boolean, range: Range, _token: CancellationToken): StartTag[] {
659661
const startTags: StartTag[] = [];
660662
const document: TextDocument = documentStateContext.document;
661663
let textOffset: number = 0;
@@ -873,16 +875,18 @@ export function getCfTags(documentStateContext: DocumentStateContext, isScript:
873875
/**
874876
* Relocates cursor to the start of the tag matching the current selection
875877
* @param editor The text editor in which to find the matching tag
878+
* @param edit
879+
* @param _token
876880
*/
877-
export async function goToMatchingTag(editor: TextEditor): Promise<void> {
881+
export async function goToMatchingTag(editor: TextEditor, edit: TextEditorEdit, _token: CancellationToken = null): Promise<void> {
878882

879883
const position: Position = editor.selection.active;
880884
const documentUri: Uri = editor.document.uri;
881885

882886
const cfmlCompletionSettings: WorkspaceConfiguration = workspace.getConfiguration("cfml.suggest", documentUri);
883887
const replaceComments = cfmlCompletionSettings.get<boolean>("replaceComments", true);
884888

885-
const documentPositionStateContext: DocumentPositionStateContext = getDocumentPositionStateContext(editor.document, position, false, replaceComments);
889+
const documentPositionStateContext: DocumentPositionStateContext = getDocumentPositionStateContext(editor.document, position, false, replaceComments, _token);
886890

887891
const currentWord: string = documentPositionStateContext.currentWord;
888892
let globalTag: GlobalTag = getGlobalTag(currentWord);

0 commit comments

Comments
 (0)