Skip to content

Commit

Permalink
Merge pull request #43 from zazuko/BenjaminHofstetter/issue42
Browse files Browse the repository at this point in the history
Simpler JSONLD support
  • Loading branch information
BenjaminHofstetter authored Dec 11, 2024
2 parents 26306ea + 9f4c5c5 commit 00daeac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
6 changes: 6 additions & 0 deletions src-vscode/src/constant/rdf-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -60,5 +65,6 @@ export interface RdfFormat {
name: string;
type: RdfSerializationType;
vscodeLanguageId: string;
vscodeFileExtension: string;
}

11 changes: 8 additions & 3 deletions src-vscode/src/rdf-preview-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 00daeac

Please sign in to comment.