Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (Navigatable.is(widget)) {
const resourceUri = widget.getResourceUri();
if (resourceUri) {
// Get the list of problem markers for the given resource URI.
const markers: Marker[] = this.problemManager.findMarkers({ uri: resourceUri });
// If no markers are available, return early.
if (markers.length === 0) {
return [];
}
// Store the marker with the highest severity.
let maxSeverity: Marker | undefined;
// Iterate over available markers to determine that which has the highest severity.
// Only display a decoration if an error or warning marker is available.
for (const marker of markers) {
// Break early if an error marker is present, since it represents the highest severity.
if (marker.data.severity === DiagnosticSeverity.Error) {
maxSeverity = marker;
break;
} else if (marker.data.severity === DiagnosticSeverity.Warning) {
maxSeverity = marker;
}
}
// Decorate the tabbar with the highest marker severity if available.
return maxSeverity ? [this.toDecorator(maxSeverity)] : [];
}
}
return [];
}
import {Point} from 'simple-text-buffer';
import {DiagnosticSeverity} from 'vscode-languageserver-types';
import invariant from 'assert';
import nullthrows from 'nullthrows';
import URI from 'vscode-uri';
const FlowSeverity = {
Error: 'Error',
Warning: 'Warning',
};
const flowSeverityToLSPSeverityMap: {
[string]: DiagnosticSeverityType,
} = {
[FlowSeverity.Error]: DiagnosticSeverity.Error,
[FlowSeverity.Warning]: DiagnosticSeverity.Warning,
};
const FILE_PROTOCOL = 'file://';
export function toURI(filePath: string): URI {
return URI.file(filePath);
}
export function fileURIToPath(fileUri: string): string {
if (process.platform !== 'win32') {
return URI.parse(fileUri).fsPath;
}
// On Windows, vscode-uri converts drive paths to lowercase,
// which Flow doesn't like very much.
return rawTemplateDiagnostics.filter(templateDiagnosticFilter).map(diag => {
// syntactic/semantic diagnostic always has start and length
// so we can safely cast diag to TextSpan
return {
range: mapBackRange(templateDoc, diag as ts.TextSpan, templateSourceMap),
severity: DiagnosticSeverity.Error,
message: ts.flattenDiagnosticMessageText(diag.messageText, '\n'),
code: diag.code,
source: 'Vetur'
};
});
}
return tests.reduce((diagnosticGroup: Map, test: Test): Map => {
const diagnostics: Diagnostic[] = diagnosticGroup.get(test.uri) || [];
if (test.type === Type.PASSED) {
return diagnosticGroup.set(test.uri, diagnostics);
}
const fault: Fault = test.fault;
const message: string = fault.message || '';
const details: Detail[] = fault.details || [];
diagnostics.push({
severity: test.type === Type.RISKY ? DiagnosticSeverity.Warning : DiagnosticSeverity.Error,
range: test.range,
message: message,
relatedInformation: this.asDiagnosticRelationInformations(details, message),
source: 'PHPUnit',
});
return diagnosticGroup.set(test.uri, diagnostics);
}, new Map());
}
private transformToDiagonstic(test: Test): Diagnostic {
return {
severity: test.type === Type.RISKY ? DiagnosticSeverity.Warning : DiagnosticSeverity.Error,
range: test.range,
message: test.fault ? test.fault.message : '',
relatedInformation: this.transformToRelatedInformation(test),
source: 'PHPUnit',
};
}
return syntaxDiagnostics.concat(semanticDiagnostics).map((diag: ts.Diagnostic): Diagnostic => {
return {
range: convertRange(currentTextDocument, diag),
severity: DiagnosticSeverity.Error,
source: 'js',
message: ts.flattenDiagnosticMessageText(diag.messageText, '\n')
};
});
},
e.diagnostics.forEach(diag => {
const range = Range.create(0, 0, 0, 1);
const message = diag.Message;
const severity = DiagnosticSeverity.Error;
errors.push(Diagnostic.create(range, message, severity));
});
}
error.location.start +
" " +
error.location.end +
" " +
error.message;
if (!added[signature]) {
added[signature] = true;
var range = {
start: textDocument.positionAt(error.location.start),
end: textDocument.positionAt(error.location.end)
};
diagnostics.push({
severity:
idx >= currentDoc.errors.length
? DiagnosticSeverity.Warning
: DiagnosticSeverity.Error,
range: range,
message: error.message
});
}
});
}
export function severityToString(severity: DiagnosticSeverity | undefined): string {
switch (severity) {
case undefined:
case DiagnosticSeverity.Error:
return "ERROR";
case DiagnosticSeverity.Warning:
return "WARN";
default:
throw new Error(`Unexpected severity: '${severity}'.`);
}
}
let match: RegExpMatchArray | null;
const wordDefinition = /[a-zA-Z0-9_/.-]+/g;
while ((match = wordDefinition.exec(lineText))) {
const matchIndex = match.index || 0;
if (matchIndex > pos) {
return undefined;
} else if (wordDefinition.lastIndex >= pos) {
return Range.create(line, matchIndex, line, wordDefinition.lastIndex);
}
}
return undefined;
}
const severityMap = {
[LGDiagnosticSeverity.Error]: DiagnosticSeverity.Error,
[LGDiagnosticSeverity.Hint]: DiagnosticSeverity.Hint,
[LGDiagnosticSeverity.Information]: DiagnosticSeverity.Information,
[LGDiagnosticSeverity.Warning]: DiagnosticSeverity.Warning,
};
export function convertSeverity(severity: LGDiagnosticSeverity): DiagnosticSeverity {
return severityMap[severity];
}
export function convertDiagnostics(lgDiags: LGDiagnostic[] = [], document: TextDocument, lineOffset = 0): Diagnostic[] {
const diagnostics: Diagnostic[] = [];
lgDiags.forEach(diag => {
const diagnostic: Diagnostic = {
severity: convertSeverity(diag.Severity),
range: Range.create(
Position.create(diag.Range.Start.Line - 1 - lineOffset, diag.Range.Start.Character),