This commit is contained in:
Jan Dolejsi
2019-11-11 01:16:15 +01:00
parent 4c16ae3106
commit dfe4bba9a3
2 changed files with 2 additions and 29 deletions

View File

@ -1,6 +1,6 @@
# 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.
![Sample](demo.gif)
@ -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
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.

View File

@ -88,33 +88,6 @@ export class FoodPyramidHierarchyProvider implements CallHierarchyProvider {
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 }));
}
}
/**