diff --git a/src-vscode/package.json b/src-vscode/package.json index 307040c..020946c 100644 --- a/src-vscode/package.json +++ b/src-vscode/package.json @@ -35,7 +35,7 @@ "menus": { "editor/title": [ { - "when": "resourceLangId == turtle || resourceLangId === n-quads || resourceLangId == jsonld || resourceLangId == ntriples || resourceLangId == rdf-xml || resourceLangId == trig", + "when": "resourceLangId == turtle || resourceLangId === n-quads || resourceLangId == ntriples || resourceLangId == rdf-xml || resourceLangId == trig || resourceExtname == .jsonld", "command": "rdf-sketch.openPreview", "group": "navigation", "icon": "$(open-preview)", diff --git a/src-vscode/src/constant/rdf-formats.ts b/src-vscode/src/constant/rdf-formats.ts index 001543f..89d3e44 100644 --- a/src-vscode/src/constant/rdf-formats.ts +++ b/src-vscode/src/constant/rdf-formats.ts @@ -14,30 +14,35 @@ export const rdfFormats: RdfFormat[] = [ name: 'Turtle', type: RdfSerializationType.Turtle, vscodeLanguageId: 'turtle', + vscodeFileExtension: 'ttl', }, { contentType: RdfSerializationType.JsonLD, name: 'JSON-LD', type: RdfSerializationType.JsonLD, vscodeLanguageId: 'jsonld', + vscodeFileExtension: 'jsonld', }, { contentType: RdfSerializationType.Trig, name: 'TriG', type: RdfSerializationType.Trig, vscodeLanguageId: 'trig', + vscodeFileExtension: 'trig' }, { contentType: RdfSerializationType.NQuads, name: 'N-Quads', type: RdfSerializationType.NQuads, vscodeLanguageId: 'n-quads', + vscodeFileExtension: 'nq' }, { contentType: RdfSerializationType.NTriples, name: 'N-Triples', type: RdfSerializationType.NTriples, vscodeLanguageId: 'ntriples', + vscodeFileExtension: 'nt' }, /* { contentType: RdfSerializationType.N3, @@ -60,5 +65,6 @@ export interface RdfFormat { name: string; type: RdfSerializationType; vscodeLanguageId: string; + vscodeFileExtension: string; } diff --git a/src-vscode/src/rdf-preview-panel.ts b/src-vscode/src/rdf-preview-panel.ts index 8ab3549..9fc8856 100644 --- a/src-vscode/src/rdf-preview-panel.ts +++ b/src-vscode/src/rdf-preview-panel.ts @@ -128,12 +128,17 @@ export class RdfPreviewPanel { updateWebviewContent = (document: TextDocument, reason: string) => { const rdfString = document.getText(); - const language = document.languageId; - const rdfFormatForVscodeLanguage = rdfFormats.find((format) => format.vscodeLanguageId === language); + const languageId = document.languageId; + const fileExtension = document.fileName.split('.').pop(); + let rdfFormatForVscodeLanguage = rdfFormats.find((format) => format.vscodeLanguageId === languageId); + + if (rdfFormatForVscodeLanguage === undefined) { + rdfFormatForVscodeLanguage = rdfFormats.find((format) => format.vscodeFileExtension === fileExtension); + } if (!rdfFormatForVscodeLanguage) { - window.showErrorMessage(`No RDF format found for language ${language}`); + window.showErrorMessage(`No RDF format found for language ${languageId} and file extension ${fileExtension}`); return; }