Skip to content

Commit a844ac0

Browse files
committed
wip
wip fix gtags
1 parent 878addd commit a844ac0

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

api/handlers_analysis.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ func (h *Handler) handleDefinition(w http.ResponseWriter, r *http.Request) {
147147
if useGtags {
148148
slog.Debug("definition gtags", "hroot", hroot, "dir", dir)
149149
h, e = search.GtagsFindDefinitions(r.Context(), word, hroot)
150+
if e != nil {
151+
slog.Warn("definition gtags error, falling back", "word", word, "err", e)
152+
e = nil
153+
}
150154
slog.Debug("definition gtags result", "word", word, "hits", len(h), "dir", dir, "elapsed", time.Since(t0))
151-
if len(h) == 0 && e == nil {
152-
// gtags miss → ctags fallback(#define マクロ等 gtags が未インデックスのシンボルをカバー)
155+
if len(h) == 0 {
156+
// gtags miss/error → ctags fallback
153157
if search.CtagsIndexed(hroot) {
154158
slog.Debug("definition gtags miss, fallback to ctags", "word", word)
155159
t0 = time.Now()

search/gtags.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ func GtagsBuildIndexStream(ctx context.Context, dir string, w io.Writer) error {
267267
// Windows ではパイプバッファリングにより出力が遅延するため、5 秒ごとにハートビートを送る。
268268
func GtagsUpdateIndexStream(ctx context.Context, dir string, w io.Writer) error {
269269
cmd := exec.CommandContext(ctx, resolveGlobalBin(), "-u", "-v")
270-
cmd.Env = englishEnv("GTAGSDBPATH="+dir, "GTAGSROOT="+dir)
270+
gtagsPathU := filepath.ToSlash(dir)
271+
cmd.Env = englishEnv("GTAGSDBPATH="+gtagsPathU, "GTAGSROOT="+gtagsPathU)
271272

272273
pr, pw := io.Pipe()
273274
cmd.Stdout = pw
@@ -382,7 +383,9 @@ func GtagsFindDefinitions(ctx context.Context, word, dir string) ([]DefHit, erro
382383
// キャンセルされても結果はキャッシュに入るので次回即返せる。
383384
cmd := exec.CommandContext(context.Background(), globalBin, "-xd", word)
384385
cmd.Dir = dir
385-
env := append(os.Environ(), "GTAGSDBPATH="+dir, "GTAGSROOT="+dir)
386+
// MSYS2版 global.exe はバックスラッシュを解釈できないためフォワードスラッシュに変換する
387+
gtagsPath := filepath.ToSlash(dir)
388+
env := append(os.Environ(), "GTAGSDBPATH="+gtagsPath, "GTAGSROOT="+gtagsPath)
386389
cmd.Env = env
387390
if devNull, err := os.Open(os.DevNull); err == nil {
388391
cmd.Stdin = devNull
@@ -855,7 +858,8 @@ func GtagsFindHoverHits(ctx context.Context, word, dir string) ([]DefHit, error)
855858
func GtagsFindRefs(ctx context.Context, word, dir string) ([]CallSite, error) {
856859
cmd := exec.CommandContext(context.Background(), resolveGlobalBin(), "-xr", word)
857860
cmd.Dir = dir
858-
cmd.Env = append(os.Environ(), "GTAGSDBPATH="+dir, "GTAGSROOT="+dir)
861+
gtagsRefPath := filepath.ToSlash(dir)
862+
cmd.Env = append(os.Environ(), "GTAGSDBPATH="+gtagsRefPath, "GTAGSROOT="+gtagsRefPath)
859863
var stderr bytes.Buffer
860864
cmd.Stderr = &stderr
861865
out, err := cmd.Output()

static/js/gtags.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,22 @@ function renderPopover() {
252252
<span>ripgrep</span>
253253
</label>`;
254254

255-
// インデックス操作(選択中エンジンに応じて切り替え)
255+
// インデックス操作
256256
html += `<div class="gtags-pop-divider"></div>`;
257257
if (eng === 'ctags' || (!_installed && ctagsIndexed)) {
258258
// ctags インデックス操作
259-
const ctagsInstalled = typeof window._ctagsInstalled === 'function' ? window._ctagsInstalled() : true;
260259
html += `<div class="gtags-pop-section">ctags インデックス</div>`;
261260
if (ctagsIndexed) {
262261
html += `<button class="gtags-pop-btn" id="ctags-pop-rebuild-main" style="width:100%">再生成</button>`;
263262
} else {
264263
html += `<button class="gtags-pop-btn primary" id="ctags-pop-build-main" style="width:100%">生成</button>`;
265264
}
265+
// GNU Global がインストール済みで未生成の場合、選択できるよう生成ボタンも表示
266+
if (_installed && !_indexed) {
267+
html += `<div class="gtags-pop-divider"></div>`;
268+
html += `<div class="gtags-pop-section">GNU Global インデックス</div>`;
269+
html += `<button class="gtags-pop-btn primary" id="gtags-pop-build" style="width:100%">生成</button>`;
270+
}
266271
} else if (_installed) {
267272
// gtags インデックス操作
268273
html += `<div class="gtags-pop-section">GNU Global インデックス</div>`;

0 commit comments

Comments
 (0)