vscode#DefinitionLink TypeScript Examples
The following examples show how to use
vscode#DefinitionLink.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: macroDefinitionProvider.ts From vscode-dbt-power-user with MIT License | 6 votes |
provideDefinition(
document: TextDocument,
position: Position
): ProviderResult<Definition | DefinitionLink[]> {
return new Promise((resolve, reject) => {
const textLine = document.lineAt(position).text;
const range = document.getWordRangeAtPosition(
position,
MacroDefinitionProvider.IS_MACRO
);
const word = document.getText(range);
if (
range &&
textLine[range.end.character] === "(" &&
isEnclosedWithinCodeBlock(document, range)
) {
const packageName = this.dbtProjectContainer.getPackageName(
document.uri
);
const macroName =
packageName !== undefined && !word.includes(".")
? `${packageName}.${word}`
: word;
const definition = this.getMacroDefinition(macroName, document.uri);
if (definition !== undefined) {
resolve(definition);
return;
}
}
reject();
});
}
Example #2
Source File: modelDefinitionProvider.ts From vscode-dbt-power-user with MIT License | 6 votes |
provideDefinition(
document: TextDocument,
position: Position,
token: CancellationToken
): ProviderResult<Definition | DefinitionLink[]> {
return new Promise((resolve, reject) => {
const hover = document.getText(document.getWordRangeAtPosition(position));
const word = document.getText(
document.getWordRangeAtPosition(
position,
ModelDefinitionProvider.IS_REF
)
);
if (word !== undefined && hover !== "ref") {
const dbtModel = word.match(ModelDefinitionProvider.GET_DBT_MODEL);
if (dbtModel && dbtModel.length === 1) {
const definition = this.getDefinitionFor(dbtModel[0], document.uri);
resolve(definition);
return;
}
}
reject();
});
}
Example #3
Source File: sourceDefinitionProvider.ts From vscode-dbt-power-user with MIT License | 5 votes |
provideDefinition(
document: TextDocument,
position: Position,
token: CancellationToken
): ProviderResult<Definition | DefinitionLink[]> {
return new Promise((resolve, reject) => {
const hover = document.getText(document.getWordRangeAtPosition(position));
const range = document.getWordRangeAtPosition(
position,
SourceDefinitionProvider.IS_SOURCE
);
const word = document.getText(range);
const linePrefix = document
.lineAt(position)
.text.substr(0, position.character);
if (
!isEnclosedWithinCodeBlock(document, position) ||
!linePrefix.includes("source") ||
hover === "source"
) {
reject();
return;
}
const source = word.match(SourceDefinitionProvider.GET_SOURCE_INFO);
if (source === null || source === undefined) {
reject();
return;
}
if (source.length < 2) {
reject();
return;
}
const definition = this.getSourceDefinition(
source[0],
document.uri,
source[1],
);
resolve(definition);
});
}