Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 20x 20x 233x 197x 36x 36x 32x 4x 4x | import { IToken, RdfToken } from '@faubulous/mentor-rdf-parsers';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-types';
import { getIriFromIriReference } from '@src/utilities';
import { LintingContext, LintingProvider } from '..';
/**
* The diagnostic code for deprecated `workspace:/path` URIs.
*/
export const DEPRECATED_WORKSPACE_URI_CODE = 'DeprecatedWorkspaceUri';
/**
* Matches the deprecated `workspace:/path` format (single slash) but NOT the
* canonical `workspace:///path` format (triple slash).
*/
const DEPRECATED_URI_REGEX = /^workspace:\/(?!\/)/;
/**
* Detects deprecated `workspace:/path` URIs in IRIREF tokens and suggests
* replacing them with `workspace:///path`.
*/
export class DeprecatedWorkspaceUriLinter implements LintingProvider {
visitToken(context: LintingContext, token: IToken, _index: number): Diagnostic[] {
if (token.tokenType?.name !== RdfToken.IRIREF.name) {
return [];
}
const iri = getIriFromIriReference(token.image);
if (!DEPRECATED_URI_REGEX.test(iri)) {
return [];
}
const canonical = iri.replace(/^workspace:\/(?!\/)/, 'workspace:///');
return [{
code: DEPRECATED_WORKSPACE_URI_CODE,
severity: DiagnosticSeverity.Warning,
message: `Deprecated workspace URI scheme. Use '${canonical}' instead.`,
source: 'Mentor',
range: {
start: context.positionAt(token.startOffset),
end: context.positionAt((token.endOffset ?? token.startOffset) + 1),
}
}];
}
}
|