vscode#DiagnosticSeverity TypeScript Examples
The following examples show how to use
vscode#DiagnosticSeverity.
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: Configuration.ts From vscode-alxmldocumentation with MIT License | 6 votes |
/**
* Returns DiagnosticSeverity for procedures as configured.
* @param fileUri
*/
public static GetProcedureDocumentationCheckInformationLevel(fileUri: Uri | undefined = undefined): DiagnosticSeverity {
switch (this.GetConfigurationValue('CheckProcedureDocumentationInformationLevel', fileUri)) {
case 'Information':
return DiagnosticSeverity.Information;
case 'Warning':
return DiagnosticSeverity.Warning;
case 'Error':
return DiagnosticSeverity.Error;
}
return DiagnosticSeverity.Information;
}
Example #2
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 #3
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 #4
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private async validateProperties() {
const properties = Object.values<string>(ConfigurationProperty);
const symbols = await this._symbolsPromise;
if (!symbols) {
return;
}
const diagnose = Diagnostics.instance.createDiagnostics(this._uri, "objidconfig.properties");
for (let symbol of symbols) {
if (!properties.includes(symbol.name)) {
diagnose(
symbol.selectionRange,
`Property "${symbol.name}" is not valid in this context`,
DiagnosticSeverity.Warning,
DIAGNOSTIC_CODE.OBJIDCONFIG.INVALID_PROPERTY
);
}
}
}
Example #5
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private makeSurePropertyIsValidPositiveInteger(
value: number,
symbol: DocumentSymbol,
diagnose: CreateDiagnostic
): boolean {
if (!value || value !== parseFloat(symbol.detail) || value < 0) {
diagnose(
this.getDetailRange(symbol),
`A valid positive integer expected`,
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.IDRANGES_INVALID_NUMBER
);
return false;
}
return true;
}
Example #6
Source File: ObjIdConfigLinter.ts From al-objid with MIT License | 6 votes |
private makeSurePropertyIsDefined(
property: DocumentSymbol | undefined,
symbol: DocumentSymbol,
name: string,
diagnose: CreateDiagnostic
): boolean {
if (!property) {
diagnose(
symbol.selectionRange,
`Missing property: ${name}`,
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.OBJIDCONFIG.MISSING_PROPERTY
);
return false;
}
return true;
}
Example #7
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 #8
Source File: stripeLinter.ts From vscode-stripe with MIT License | 6 votes |
// prepareAPIKeyDiagnostics regex matches all instances of a Stripe API Key in a supplied line of text
// will return a list of Diagnostics pointing at instances of the Stripe API Keys it found
prepareLineDiagnostics =
(message: string) =>
(line: string, index: number): Diagnostic[] => {
const diagnostics: Diagnostic[] = [];
let match;
while ((match = stripeKeysRegex.exec(line)) !== null) {
const severity = /sk_live/.test(match[0])
? DiagnosticSeverity.Error
: DiagnosticSeverity.Warning;
// specify line and character range to draw the squiggly line under the API Key in the document
const range = new Range(index, match.index, index, match.index + match[0].length);
// create new diagnostic and add to the list of total diagnostics for this line of code
const diagnostic = new Diagnostic(range, message, severity);
this.telemetry.sendEvent('diagnostics.show', severity);
diagnostics.push(diagnostic);
}
return diagnostics;
};
Example #9
Source File: sqlFluffLinter.ts From vscode-sqlfluff with MIT License | 6 votes |
public process(lines: string[]): Diagnostic[] {
let diagnostics: Diagnostic[] = [];
lines.forEach((line) => {
let filePaths: Array<FilePath> = JSON.parse(line);
filePaths.forEach((filePath: FilePath) => {
filePath.violations.forEach((violation: Violation) => {
diagnostics.push({
range: new Range(violation.line_no-1, violation.line_pos, violation.line_no-1, violation.line_pos),
severity: DiagnosticSeverity.Error,
message: violation.description,
code: violation.code,
source: 'sqlfluff'
});
});
});
});
return diagnostics;
}
Example #10
Source File: parser.ts From vscode-discord with MIT License | 6 votes |
public diagnosticsChange() {
const diag = languages.getDiagnostics();
let counted: number = 0;
diag.forEach((i) => {
if (i[1])
i[1].forEach((i) => {
if (
i.severity == DiagnosticSeverity.Warning ||
i.severity == DiagnosticSeverity.Error
)
counted++;
});
});
this.problems = counted;
}
Example #11
Source File: extension.test.ts From typescript-explicit-types with GNU General Public License v3.0 | 6 votes |
performTypeGeneration = async (element: string, document: TextDocument, { expectedType }: TypeGenerationOptions = {}) => {
let fileText = document.getText();
const f1Position = fileText.indexOf(element);
const wordRange = document.getWordRangeAtPosition(document.positionAt(f1Position));
if (!wordRange) {
assert.fail(`${element} not found in file`);
}
const actions = await executeCodeActionProvider(document.uri, wordRange);
const generateAction = actions?.find((action) => action.command!.command === commandId);
if (!generateAction) assert.fail('Generate action not found');
const command = generateAction.command!;
await commands.executeCommand.apply(null, [command.command, ...command.arguments!]);
if (expectedType) {
fileText = document.getText();
const res = fileText.includes(`${element}: ${expectedType}`);
assert.strictEqual(res, true);
} else {
const diagnostics = languages
.getDiagnostics(document.uri)
.filter((x) => [DiagnosticSeverity.Error, DiagnosticSeverity.Warning].includes(x.severity));
assert.strictEqual(diagnostics.length, 0, JSON.stringify(diagnostics));
}
}
Example #12
Source File: holes.ts From vscode-lean4 with Apache License 2.0 | 6 votes |
private async refresh() {
const ress = await Promise.all(window.visibleTextEditors
.filter((editor) => languages.match(this.leanDocs, editor.document))
.map((editor) => this.server.allHoleCommands(editor.document.fileName)));
this.holes = [];
for (const res of ress) {
[].push.apply(this.holes, res.holes);
}
const holesPerFile = new Map<string, HoleCommands[]>();
for (const hole of this.holes) {
if (!holesPerFile.get(hole.file)) { holesPerFile.set(hole.file, []); }
holesPerFile.get(hole.file).push(hole);
}
this.collection.clear();
for (const file of holesPerFile.keys()) {
this.collection.set(Uri.file(file),
holesPerFile.get(file).map((hole) =>
new Diagnostic(mkRange(hole),
'Hole: ' + hole.results.map((a) => a.name).join('/'),
DiagnosticSeverity.Hint)));
}
}
Example #13
Source File: yaccValidation.ts From yash with MIT License | 6 votes |
export function doYACCValidation(document: TextDocument, yaccDocument: YACCDocument): Diagnostic[] {
const diags: Diagnostic[] = [];
yaccDocument.problems.forEach(problem => {
const range = new Range(document.positionAt(problem.offset), document.positionAt(problem.end));
let severity: DiagnosticSeverity = DiagnosticSeverity.Information;
switch (problem.type) {
case ProblemType.Error:
severity = DiagnosticSeverity.Error;
break;
case ProblemType.Information:
severity = DiagnosticSeverity.Information;
break;
case ProblemType.Warning:
severity = DiagnosticSeverity.Warning;
break;
}
const diag = new Diagnostic(range, problem.message, severity);
if (problem.related) {
diag.relatedInformation = [new DiagnosticRelatedInformation(
new Location(document.uri, new Range(document.positionAt(problem.related.offset), document.positionAt(problem.related.end))),
problem.related.message
)];
}
diags.push(diag);
});
return diags;
}
Example #14
Source File: lexValidation.ts From yash with MIT License | 6 votes |
export function doLEXValidation(document: TextDocument, lexDocument: LexDocument): Diagnostic[] {
const diags: Diagnostic[] = [];
lexDocument.problems.forEach(problem => {
const range = new Range(document.positionAt(problem.offset), document.positionAt(problem.end));
let severity: DiagnosticSeverity = DiagnosticSeverity.Information;
switch (problem.type) {
case ProblemType.Error:
severity = DiagnosticSeverity.Error;
break;
case ProblemType.Information:
severity = DiagnosticSeverity.Information;
break;
case ProblemType.Warning:
severity = DiagnosticSeverity.Warning;
break;
}
const diag = new Diagnostic(range, problem.message, severity);
if (problem.related) {
diag.relatedInformation = [new DiagnosticRelatedInformation(
new Location(document.uri, new Range(document.positionAt(problem.related.offset), document.positionAt(problem.related.end))),
problem.related.message
)];
}
diags.push(diag);
});
return diags;
}
Example #15
Source File: parseSPCompErrors.ts From sourcepawn-vscode with MIT License | 6 votes |
export function parseSPCompErrors(
stdout: string,
compilerDiagnostics: DiagnosticCollection,
filePath?: string
): void {
const DocumentDiagnostics: Map<string, Diagnostic[]> = new Map();
const re = /([:\/\\A-Za-z\-_0-9. ]*)\((\d+)+\) : ((error|fatal error|warning) ([0-9]*)):\s+(.*)/gm;
let matches: RegExpExecArray | null;
let diagnostics: Diagnostic[];
do {
matches = re.exec(stdout.toString() || "");
if (matches) {
let range = new Range(
new Position(Number(matches[2]) - 1, 0),
new Position(Number(matches[2]) - 1, 256)
);
let severity =
matches[4] === "warning"
? DiagnosticSeverity.Warning
: DiagnosticSeverity.Error;
let uri = URI.file(
filePath === undefined ? matches[1] : filePath
).toString();
diagnostics = DocumentDiagnostics.get(uri) || [];
let message: string = generateDetailedError(matches[5], matches[6]);
let diagnostic: Diagnostic = new Diagnostic(range, message, severity);
diagnostics.push(diagnostic);
DocumentDiagnostics.set(uri, diagnostics);
}
} while (matches);
compilerDiagnostics.clear();
for (let [uri, diagnostics] of DocumentDiagnostics) {
compilerDiagnostics.set(URI.parse(uri), diagnostics);
}
}
Example #16
Source File: Configuration.ts From vscode-alxmldocumentation with MIT License | 6 votes |
/**
* Returns DiagnosticSeverity for objects as configured.
* @param fileUri
*/
public static GetObjectDocumentationCheckInformationLevel(fileUri: Uri | undefined = undefined): DiagnosticSeverity {
switch (this.GetConfigurationValue('CheckObjectDocumentationInformationLevel', fileUri)) {
case 'Information':
return DiagnosticSeverity.Information;
case 'Warning':
return DiagnosticSeverity.Warning;
case 'Error':
return DiagnosticSeverity.Error;
}
return DiagnosticSeverity.Information;
}
Example #17
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 #18
Source File: BCLicense.ts From al-objid with MIT License | 5 votes |
public async validate() {
const uris = await getWorkspaceFolderFiles(this._uri);
const objects = await getObjectDefinitions(uris);
let cache: PropertyBag<any> = {};
let uriCache: PropertyBag<Uri> = {};
for (let object of objects) {
if (!uriCache[object.path]) {
const uri = Uri.file(object.path);
uriCache[object.path] = uri;
}
const objectUri = uriCache[object.path];
const diagnose = Diagnostics.instance.createDiagnostics(objectUri, `bclicense.${object.type}.${object.id}`);
const mappedType = objectTypeToPermissionTypeMap[object.type];
let permissions = cache[mappedType];
if (!permissions) {
const setup = this._data.License.PermissionCollections[0].pl.find(
(obj: any) => obj?.$?.t === mappedType
);
cache[mappedType] = setup;
}
permissions = cache[mappedType];
if (permissions) {
const range = permissions?.ps[0]?.p?.find(
(line: any) => line?.$?.f <= object.id && line?.$?.t >= object.id
);
if (range) {
if ((range?.$?.pbm & 2) === 2) {
continue;
}
}
diagnose(
new Range(
new Position(object.line, object.character),
new Position(object.line, object.character + object.id.toString().length)
),
`${object.type} ${object.id} is not included in the license`,
DiagnosticSeverity.Error,
DIAGNOSTIC_CODE.BCLICENSE.UNAVAILABLE
);
}
}
}