mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
clean-up
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
# Call Hierarchy Provider Sample
|
# Call Hierarchy Provider Sample
|
||||||
|
|
||||||
This sample shows the **Call Hierarchy** in action based on a simple food pyramid model defined using simple subject~verb~object syntax.
|
This sample shows the **Call Hierarchy** in action based on a simple food pyramid model defined using simple subject ~ verb ~ object syntax.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -31,4 +31,4 @@ Right click on a noun or a verb and select _Peek Call Hierarchy_.
|
|||||||
|
|
||||||
## Contributing to the Sample and Testing the Sample
|
## Contributing to the Sample and Testing the Sample
|
||||||
|
|
||||||
Run the _Run Extension Tests_ configuration and verify in the Debug Console that all tests are passing.
|
Run the _Run Extension Tests_ configuration and verify in the Debug Console that all tests are passing.
|
||||||
|
|||||||
@ -88,33 +88,6 @@ export class FoodPyramidHierarchyProvider implements CallHierarchyProvider {
|
|||||||
return new CallHierarchyItem(SymbolKind.Object, word, `(${type})`, document.uri, range, range);
|
return new CallHierarchyItem(SymbolKind.Object, word, `(${type})`, document.uri, range, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
deriveCalledItem(item: CallHierarchyItem, called: string, document: TextDocument): CallHierarchyOutgoingCall {
|
|
||||||
const range = this.rangeOf(called, document);
|
|
||||||
let calledItem = new CallHierarchyItem(item.kind, called, called, item.uri, range, range);
|
|
||||||
return new CallHierarchyOutgoingCall(calledItem, this.allRangesOf(called, document));
|
|
||||||
}
|
|
||||||
|
|
||||||
rangeOf(word: string, document: TextDocument): Range {
|
|
||||||
let match = new RegExp("\\b" + word + "\\b").exec(document.getText());
|
|
||||||
let offset = match!.index;
|
|
||||||
return this.toRange(document, offset, word);
|
|
||||||
}
|
|
||||||
|
|
||||||
allRangesOf(word: string, document: TextDocument): Range[] {
|
|
||||||
let pattern = new RegExp("\b" + word + "\b");
|
|
||||||
let ranges: Range[] = [];
|
|
||||||
|
|
||||||
var match: RegExpExecArray | null;
|
|
||||||
while (match = pattern.exec(document.getText())) {
|
|
||||||
ranges.push(this.toRange(document, match.index, word));
|
|
||||||
}
|
|
||||||
return ranges;
|
|
||||||
}
|
|
||||||
|
|
||||||
private toRange(document: TextDocument, offset: number, word: string) {
|
|
||||||
let position = document.positionAt(offset);
|
|
||||||
return new Range(position, position.translate({ characterDelta: word.length }));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user