vscode#SymbolKind TypeScript Examples
The following examples show how to use
vscode#SymbolKind.
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: spTypesetItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description,
SymbolKind.TypeParameter,
this.fullRange,
this.range
);
}
Example #2
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private async validateAppPoolId() {
const appPoolId = await this._appPoolIdPromise;
if (!appPoolId) {
return;
}
const diagnose = Diagnostics.instance.createDiagnostics(this._uri, "objidconfig.appPoolId");
this.expectType(appPoolId, SymbolKind.String, "String", diagnose);
}
Example #3
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private async validateAuthKey() {
const authKey = await this._authKeyPromise;
if (!authKey) {
return;
}
const diagnose = Diagnostics.instance.createDiagnostics(this._uri, "objidconfig.authKey");
this.expectType(authKey, SymbolKind.String, "String", diagnose);
}
Example #4
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private async validateBcLicense() {
const bcLicense = await this._bcLicensePromise;
if (!bcLicense) {
return;
}
const diagnose = Diagnostics.instance.createDiagnostics(this._uri, "objidconfig.bcLicense");
this.expectType(bcLicense, SymbolKind.String, "String", diagnose);
const relativePath = bcLicense.detail;
const bcLicensePath = path.isAbsolute(relativePath)
? relativePath
: path.join(workspace.getWorkspaceFolder(this._uri)!.uri.fsPath, relativePath);
if (!fs.existsSync(bcLicensePath)) {
diagnose(
this.getDetailRange(bcLicense),
"License file does not exist",
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.LICENSE_FILE_NOT_FOUND
);
return;
}
const license = new BCLicense(bcLicensePath);
if (!license.isValid) {
diagnose(
this.getDetailRange(bcLicense),
"Invalid license file",
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.LICENSE_FILE_INVALID
);
}
}
Example #5
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private async validateObjectTypes() {
const objectRanges = await this._objectRangesPromise;
if (!objectRanges) {
return;
}
const diagnose = Diagnostics.instance.createDiagnostics(this._uri, "objidconfig.objectRanges");
const validTypes = Object.values<string>(ALObjectType);
if (!this.expectType(objectRanges, SymbolKind.Module, "Object", diagnose)) {
return;
}
for (let child of objectRanges.children) {
const type = child.name;
if (!validTypes.includes(type)) {
diagnose(
child.selectionRange,
`Invalid object type: ${type}.`,
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.INVALID_OBJECT_TYPE
);
continue;
}
this.validateRanges(child, diagnose);
}
}
Example #6
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private expectType(
symbol: DocumentSymbol,
expectedKind: SymbolKind,
type: string,
diagnose: CreateDiagnostic
): boolean {
if (symbol.kind !== expectedKind) {
diagnose(
this.getDetailRange(symbol),
`${type} expected`,
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.IDRANGES_INVALID_TYPE
);
return false;
}
return true;
}
Example #7
Source File: CodeLinkFeature.ts From vscode-drawio with GNU General Public License v3.0 | 6 votes |
symbolNameMap: Record<SymbolKind, string> = {
[SymbolKind.File]: "symbol-file",
[SymbolKind.Module]: "symbol-module",
[SymbolKind.Namespace]: "symbol-namespace",
[SymbolKind.Package]: "symbol-package",
[SymbolKind.Class]: "symbol-class",
[SymbolKind.Method]: "symbol-method",
[SymbolKind.Property]: "symbol-property",
[SymbolKind.Field]: "symbol-field",
[SymbolKind.Constructor]: "symbol-constructor",
[SymbolKind.Enum]: "symbol-enum",
[SymbolKind.Interface]: "symbol-interface",
[SymbolKind.Function]: "symbol-function",
[SymbolKind.Variable]: "symbol-variable",
[SymbolKind.Constant]: "symbol-constant",
[SymbolKind.String]: "symbol-string",
[SymbolKind.Number]: "symbol-number",
[SymbolKind.Boolean]: "symbol-boolean",
[SymbolKind.Array]: "symbol-array",
[SymbolKind.Object]: "symbol-object",
[SymbolKind.Key]: "symbol-key",
[SymbolKind.Null]: "symbol-null",
[SymbolKind.EnumMember]: "symbol-enum-member",
[SymbolKind.Struct]: "symbol-struct",
[SymbolKind.Event]: "symbol-event",
[SymbolKind.Operator]: "symbol-operator",
[SymbolKind.TypeParameter]: "symbol-type-parameter",
}
Example #8
Source File: spVariableItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol {
return new DocumentSymbol(
this.name,
this.type,
SymbolKind.Variable,
this.range,
this.range
);
}
Example #9
Source File: spDefineItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description ? this.description.replace(/^\*\</, "") : "",
SymbolKind.Constant,
this.fullRange,
this.range
);
}
Example #10
Source File: spTypedefItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description,
SymbolKind.TypeParameter,
this.fullRange,
this.range
);
}
Example #11
Source File: spPropertyItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description,
SymbolKind.Property,
this.fullRange,
this.range
);
}
Example #12
Source File: spMethodmapItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description,
SymbolKind.Class,
this.fullRange,
this.range
);
}
Example #13
Source File: spMethodItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description,
SymbolKind.Method,
this.fullRange,
this.range
);
}
Example #14
Source File: spFunctionItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description,
SymbolKind.Function,
this.fullRange,
this.range
);
}
Example #15
Source File: spEnumStructItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description,
SymbolKind.Struct,
this.fullRange,
this.range
);
}
Example #16
Source File: spEnumMemberItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.name === "") {
return undefined;
}
return new DocumentSymbol(
this.name,
this.description.replace(/^\*\</, ""),
SymbolKind.Enum,
this.range,
this.range
);
}
Example #17
Source File: spEnumItem.ts From sourcepawn-vscode with MIT License | 6 votes |
toDocumentSymbol(): DocumentSymbol | undefined {
if (this.fullRange === undefined) {
return undefined;
}
return new DocumentSymbol(
this.name.replace(/Enum#(\d+)/, "Anonymous$1"),
this.description,
SymbolKind.Enum,
this.fullRange,
this.range
);
}
Example #18
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 5 votes |
private validateRanges(idRanges: DocumentSymbol, diagnose: CreateDiagnostic) {
if (!this.expectType(idRanges, SymbolKind.Array, "Array", diagnose)) {
return;
}
const ranges: ALRange[] = [];
for (let symbol of idRanges.children) {
if (!this.expectType(symbol, SymbolKind.Module, "Object", diagnose)) {
continue;
}
let fromToValid = true;
const from = symbol.children.find(child => child.name === "from");
const to = symbol.children.find(child => child.name === "to");
const description = symbol.children.find(child => child.name === "description");
if (!this.makeSurePropertyIsDefined(from, symbol, "from", diagnose)) {
fromToValid = false;
}
if (!this.makeSurePropertyIsDefined(to, symbol, "to", diagnose)) {
fromToValid = false;
}
if (from && !this.expectType(from, SymbolKind.Number, "Number", diagnose)) {
fromToValid = false;
}
if (to && !this.expectType(to, SymbolKind.Number, "Number", diagnose)) {
fromToValid = false;
}
if (to && from && fromToValid) {
fromToValid = true;
const fromValue = parseInt(from.detail);
const toValue = parseInt(to.detail);
if (!this.makeSurePropertyIsValidPositiveInteger(fromValue, from, diagnose)) {
fromToValid = false;
}
if (!this.makeSurePropertyIsValidPositiveInteger(toValue, to, diagnose)) {
fromToValid = false;
}
if (fromToValid) {
if (toValue < fromValue) {
diagnose(
this.normalizeRange(from.range, to.range),
`Invalid range: "to" must not be less than "from".`,
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.IDRANGES_TO_BEFORE_FROM
);
fromToValid = false;
}
}
if (fromToValid) {
const newRange: ALRange = { from: fromValue, to: toValue };
const overlapRange = ranges.find(range => range.from <= newRange.to && range.to >= newRange.from);
if (overlapRange) {
diagnose(
this.normalizeRange(from.range, to.range),
`Range overlaps with another range: ${JSON.stringify(overlapRange)}`,
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.IDRANGES_OVERLAP
);
} else {
ranges.push(newRange);
}
}
}
if (description) {
this.expectType(description, SymbolKind.String, "String", diagnose);
}
}
}
Example #19
Source File: actionProvider.ts From typescript-explicit-types with GNU General Public License v3.0 | 4 votes |
public async provideCodeActions(document: TextDocument, range: Range | Selection, context: CodeActionContext): Promise<CodeAction[]> {
const config = workspace.getConfiguration(configurationId);
const isPreferrable = config.get<boolean>(ConfigurationKey.preferable);
const allDefinitions: Location[] = [];
for (let lineNumber = range.start.line; lineNumber <= range.end.line; lineNumber++) {
const line = document.lineAt(lineNumber);
const startCharNumber = lineNumber === range.start.line ? range.start.character : 0;
const endCharNumber = lineNumber === range.end.line ? range.end.character : line.range.end.character;
for (let charNumber = startCharNumber; charNumber <= endCharNumber; charNumber++) {
const foundDefinitions = await executeDefinitionProvider(document.uri, new Position(lineNumber, charNumber));
if (foundDefinitions?.length) allDefinitions.push(foundDefinitions[0]);
}
}
if (!allDefinitions.length) return [];
const definitions = uniqWith(allDefinitions, (a, b) => a.originSelectionRange.isEqual(b.originSelectionRange));
const symbols = await executeSymbolProvider(document.uri);
const generateTypeInfos: GenerateTypeInfo[] = [];
for (const definition of definitions) {
const hoverRes = await executeHoverProvider(document.uri, definition.originSelectionRange.start);
if (!hoverRes) continue;
// check if definition has a typescript annotation
const tsHoverContent = hoverRes
.reduce<string[]>((acc, val) => acc.concat(val.contents.map((x) => x.value)), [])
.find((x) => x.includes('typescript'));
if (!tsHoverContent) continue;
const word = document.getText(definition.originSelectionRange);
const lineText = document.getText(document.lineAt(definition.originSelectionRange.start.line).range);
// => is recognized as a definition, but it's type is usually defined before, unlike all other types
if (word === '=>') {
// check that there are arrow functions without type on this line
const regexp = /\)\s*=>/gm;
const matches = findMatches(regexp, lineText);
const indexes = matches.map((x) => x.index);
if (!matches.length) continue;
const passedIndex = indexes.find((i) => i > definition.originSelectionRange.start.character);
// look for a potential index of a match
// there might be several arrow functions on the same line & this definition might actually be one with a type
const potentialIndexIndex = passedIndex ? indexes.indexOf(passedIndex) - 1 : indexes.length - 1;
if (potentialIndexIndex < 0) continue;
// check that our match contains the definition
const potentialIndex = indexes[potentialIndexIndex];
const definitionMatch = matches![potentialIndexIndex];
if (
potentialIndex >= definition.originSelectionRange.start.character ||
potentialIndex + definitionMatch[0].length <= definition.originSelectionRange.start.character
)
continue;
generateTypeInfos.push({
isFunction: true,
typescriptHoverResult: tsHoverContent,
typePosition: new Position(definition.originSelectionRange.start.line, potentialIndex + 1),
});
continue;
}
const symbol = symbols?.find((x) => x.selectionRange.contains(definition.originSelectionRange));
const trailingSlice = document.getText(new Range(definition.originSelectionRange.end, definition.targetRange.end));
const isFollowedByBracket = !!trailingSlice.match(/^(\s|\\[rn])*\(/);
if (symbol?.kind === SymbolKind.Function || word === 'function' || isFollowedByBracket) {
// find out suitable type position by looking for a closing bracket of the function
const offset = document.offsetAt(definition.originSelectionRange.end);
const firstBracket = trailingSlice.indexOf('(');
const closingBracketIndex = findClosingBracketMatchIndex(trailingSlice, firstBracket);
const isFunctionTyped = trailingSlice.slice(closingBracketIndex + 1).match(/^\s*:/);
if (isFunctionTyped) continue;
const definitionSlice = document.getText(definition.targetRange);
const firstSymbol = definitionSlice.match(/^\w+/);
generateTypeInfos.push({
typescriptHoverResult: tsHoverContent,
typePosition: document.positionAt(offset + closingBracketIndex + 1),
isFunction: !firstSymbol || !functionHandlerExceptions.includes(firstSymbol[0]),
});
} else {
// check if type annotation is already present
const typePosition = new Position(definition.originSelectionRange.end.line, definition.originSelectionRange.end.character);
const slice = lineText.slice(typePosition.character);
const match = slice.match(/^\s*:/g);
if (match?.length) continue;
generateTypeInfos.push({
typescriptHoverResult: tsHoverContent,
typePosition,
});
}
}
if (!generateTypeInfos.length) return [];
const action = new CodeAction('Generate explicit type', CodeActionKind.QuickFix);
const args: Parameters<typeof commandHandler> = [generateTypeInfos];
action.command = { command: 'extension.generateExplicitType', title: 'Generate explicit type', arguments: args };
action.isPreferred = isPreferrable;
return [action];
}