Skip to content

Commit

Permalink
Merge pull request #89 from zazuko/file-not-found
Browse files Browse the repository at this point in the history
fix relative patterns
  • Loading branch information
BenjaminHofstetter authored Dec 10, 2024
2 parents 44e4198 + 142029c commit df4a4bb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions samples/deep-notebook/deep-relative-path.sparqlbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"kind": 2,
"language": "sparql",
"value": "# [endpoint=../deep/deep.ttl]\n\nSELECT * WHERE {\n ?s ?p ?o\n}",
"metadata": {}
}
]
3 changes: 3 additions & 0 deletions samples/deep/deep.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@prefix ex: <http://example.org/> .

ex:A a ex:Class1 .
6 changes: 6 additions & 0 deletions samples/multi-endpoiont.sparqlbook
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,11 @@
"language": "sparql",
"value": "# [endpoint=rdf/a.ttl]\n# Test [endpoint=https://query.wikidata.org/bigdata/namespace/wdq/sparql] Test \n# \nPREFIX wd: <http://www.wikidata.org/entity/>\nPREFIX wdt: <http://www.wikidata.org/prop/direct/>\nPREFIX wikibase: <http://wikiba.se/ontology#>\nPREFIX bd: <http://www.bigdata.com/rdf#>\n\nSELECT DISTINCT ?euMemberCountry ?euMemberCountryLabel ?headOfState ?headOfStateLabel\n \nWHERE {\n ?euMemberCountry wdt:P463 wd:Q458;\n wdt:P35 ?headOfState .\n SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\". }\n}",
"metadata": {}
},
{
"kind": 2,
"language": "sparql",
"value": "# [endpoint=./deep/deep.ttl]\n\nSELECT * WHERE {\n ?s ?p ?o\n}",
"metadata": {}
}
]
14 changes: 12 additions & 2 deletions src/extension/notebook/sparql-notebook-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,21 @@ export class SparqlNotebookController {
fileUri.push(...files);
} else {
// Relative pattern
const relativePatternString = filePathPattern.startsWith('./') ? filePathPattern.replace('./', '') : filePathPattern;

const relativePatternStringFromNotebook = filePathPattern.startsWith('./') ? filePathPattern.replace('./', '') : filePathPattern;
const notebookDirectory = path.dirname(notebookUri!.fsPath);
const relativePattern = new RelativePattern(notebookDirectory, relativePatternString);
const normalizedPattern = path.normalize(path.join(notebookDirectory, filePathPattern));

const fileName = path.basename(normalizedPattern);
const directory = path.dirname(normalizedPattern);

const relativePattern = new RelativePattern(directory, fileName);
const files = await workspace.findFiles(relativePattern);

fileUri.push(...files);
if (files.length === 0) {
window.showErrorMessage(`No files found for pattern ${filePathPattern}`);
}
}

for (const uri of fileUri) {
Expand Down

0 comments on commit df4a4bb

Please sign in to comment.