Skip to content

Commit 6aa45c0

Browse files
committed
Resolve bib files even if user is not using a workspace
1 parent 2b33bf3 commit 6aa45c0

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [0.10.1] - 2023-06-08
4+
5+
- Try to fix citation autocompletion not showing up if a workspace is not loaded
6+
37
## [0.10.0] - 2023-06-07
48

59
- The bibliography paths in the YAML header no longer need to be enclosed in square brackets (issue #32)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pandocciter",
33
"displayName": "Pandoc Citer",
44
"description": "Autocomplete bibtex citations for markdown/pandoc",
5-
"version": "0.10.0",
5+
"version": "0.10.1",
66
"publisher": "notZaki",
77
"license": "MIT",
88
"engines": {

src/components/manager.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Manager {
4747

4848
const docURI = vscode.window.activeTextEditor!.document.uri;
4949
const configuration = vscode.workspace.getConfiguration('PandocCiter', docURI);
50-
const rootFolder = vscode.workspace.getWorkspaceFolder(docURI).uri.fsPath;
50+
const rootFolder = vscode.workspace.getWorkspaceFolder(docURI)?.uri.fsPath;
5151

5252
const activeText = vscode.window.activeTextEditor!.document.getText();
5353
const yamltext = activeText.match(/---\r?\n((.+\r?\n)+)---/gm)
@@ -66,7 +66,7 @@ export class Manager {
6666
const rootfile: string = configuration.get('RootFile')
6767
if (rootfile !== "") {
6868
let curInput = path.join(rootfile);
69-
if (!path.isAbsolute(curInput)) {
69+
if (!path.isAbsolute(curInput) && rootFolder) {
7070
curInput = path.join(rootFolder, rootfile);
7171
}
7272
const rootText = fs.readFileSync(curInput,'utf8');
@@ -116,8 +116,10 @@ export class Manager {
116116
resolveBibFile(bibFile: string, rootFolder: string) {
117117
if (path.isAbsolute(bibFile)) {
118118
return bibFile;
119-
} else {
119+
} else if (rootFolder) {
120120
return path.resolve(path.join(rootFolder, bibFile));
121+
} else {
122+
return path.resolve(path.dirname(vscode.window.activeTextEditor!.document.fileName), bibFile)
121123
}
122124
}
123125

0 commit comments

Comments
 (0)