https://github.com/tadashi-aikawa/obsidian-another-quick-switcher/issues/120
## [[Linux]]でデバッグの準備
前提として [[🐧Linux(Ubuntu)でObsidianをデバッグ]] する準備をしてから...
クローン。
```console
cd work
git clone https://github.com/tadashi-aikawa/obsidian-another-quick-switcher.git
```
[[Vault]]のルートは`~/tmp/testvault`なので[[Taskfile]]を変更する。
```diff
- watch: watchexec --no-vcs-ignore --exts "js,json,css" cp main.js styles.css manifest.json $USERPROFILE/work/minerva/.obsidian/plugins/obsidian-another-quick-switcher/
+ watch: watchexec --no-vcs-ignore --exts "js,json,css" cp main.js styles.css manifest.json ~/tmp/testvault/.obsidian/plugins/obsidian-another-quick-switcher/
```
[[📘Obsidianプラグイン開発で自動リロードさせる]]準備。
```console
wget https://github.com/pjeby/hot-reload/releases/download/0.1.10/hot-reload.zip
unzip *.zip
touch ~/tmp/testvault/.obsidian/plugins/obsidian-another-quick-switcher/.hotreload
```
[[Hot Reload (Obsidian)|Hot Reload]]プラグインの有効化を忘れずに。
```console
task init
task dev
```
[[Obsidian]]で[[Hot Reload (Obsidian)|Hot Reload]]の通知がくればOK。
## 再現確認
再現はする。
## ログを仕込む
コマンド前後に。
```ts
export async function rg(
cmd: string,
...args: string[]
): Promise<MatchResult[]> {
return new Promise((resolve, _) => {
execFile(
cmd,
["--json", ...args],
{ maxBuffer: 100 * 1024 * 1024 },
(_, stdout, _stderr) => {
+ console.log(stdout)
+ console.log(_stderr)
const results = stdout
.split("\n")
.filter((x: string) => x)
.map((x: string) => JSON.parse(x) as Result)
.filter((x: Result) => x.type === "match") as MatchResult[];
+ console.log(results)
resolve(results);
}
);
});
}
```
さて...どうなるか。
```txt
{"data":{"elapsed_total":{"human":"0.002831s","nanos":2830585,"secs":0},"stats":{"bytes_printed":0,"bytes_searched":0,"elapsed":{"human":"0.000000s","nanos":0,"secs":0},"matched_lines":0,"matches":0,"searches":0,"searches_with_match":0}},"type":"summary"}
ripgrep.ts:54 home/ubuntu/tmp/testvault/: No such file or directory (os error 2)
ripgrep.ts:60 []
```
なるほどな。。パスの先頭に`/`がついていない。
`GrepModa.ts`の以下
```ts
const rgResults = await rg(
this.settings.ripgrepCommand,
...[
"-t",
"md",
hasCapitalLetter ? "" : "-i",
"--",
query,
`${this.vaultRootPath}/${absolutePathFromRoot}`,
].filter((x) => x)
);
```
`this.vaultRootPath`を見ると、先頭に`/`がついていなかった。一方 `app.vault.adapter.basePath` には先頭に`/`がついていた。ここの書き換えをしているのは一か所しかない。
```ts
this.vaultRootPath = normalizePath(
(this.app.vault.adapter as any).basePath as string
);
```
この挙動は[[Windows]]でも同じだった。
```ts
const p = "/aaa/bbb\\ccc"
console.log(normalizePath(p))
// aaa/bbb/ccc
```
[[Windows]]だとたまたま`/`から始まらない絶対パスだったから動いた...と。
```ts
C:/Users/syoum/work/minerva
```
## `normalizePath`を独自実装する
ここでの要件は `\\` を `/` に変更するだけなのでそのように実装する。ついでに`normalizeRelativePath`の実装が[[Linux]]を考慮できていなかったのも修正。
https://github.com/tadashi-aikawa/obsidian-another-quick-switcher/commit/4933320158f7b551a1b8f1950a86b3486c0d847f
これで`rg`関数から結果が返却されるようになったが、suggestionsにはまだ表示されない。
## Suggestionsに表示されない理由は?
`data.path.text`が`"/home/ubuntu/tmp/testvault//Untitled.md"`となっているのが気になる。`/`が重複している。
[[Windows]]は`"C:/Users/syoum/work/minerva/📰Weekly Report\📰2022年28週 Weekly Report.md"`な感じなので`/`は重複しない。
## 対策
複数の`/`は1つにしてしまってもいいかも?
https://github.com/tadashi-aikawa/obsidian-another-quick-switcher/commit/b247eee3da273ad5c439b95c3e66a58d9a992441
[[Windows]]と[[Ubuntu Desktop]]では問題なく動いた。