项目文件夹

文件
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

55 行
2.0 KiB
Go

package lsp
import (
"crypto/sha256"
"encoding/hex"
"os"
"path/filepath"
"github.com/zzet/gortex/internal/platform"
)
// isJdtlsCommand reports whether a resolved LSP command is the Eclipse JDT
// language server, whether configured bare ("jdtls") or as an absolute path.
func isJdtlsCommand(command string) bool {
return filepath.Base(command) == "jdtls"
}
// jdtlsWorkspaceDir returns the Eclipse workspace directory jdtls should use
// for a repo root, rooted at Gortex's cache home (via internal/platform, so
// XDG_CACHE_HOME overrides win and the path is Windows-safe). Without an
// explicit -data the brew launcher defaults the workspace to
// ~/Library/Caches/jdtls/<hash> — outside the isolation every other engine
// artifact honours — and two daemons indexing the same repo path collide there.
func jdtlsWorkspaceDir(repoRoot string) string {
sum := sha256.Sum256([]byte(repoRoot))
hash := hex.EncodeToString(sum[:])[:16]
return filepath.Join(platform.CacheDir(), "lsp", "jdtls", hash)
}
// jdtlsDataArgs appends `-data <workspace>` to a jdtls launch argv unless the
// caller already pinned an explicit workspace. It creates the workspace and
// clears a stale Eclipse lock so a workspace left locked by a crashed or killed
// server does not wedge the next launch.
func jdtlsDataArgs(baseArgs []string, repoRoot string) []string {
for _, a := range baseArgs {
if a == "-data" {
return baseArgs
}
}
dir := jdtlsWorkspaceDir(repoRoot)
prepareJdtlsWorkspace(dir)
out := append([]string(nil), baseArgs...)
return append(out, "-data", dir)
}
// prepareJdtlsWorkspace ensures the workspace directory exists and removes a
// stale Eclipse lock (.metadata/.lock) left by a crashed or killed jdtls, which
// would otherwise refuse to open the workspace and wedge enrichment. Best
// effort — a live server re-creates the lock, and any error is non-fatal so a
// launch is never blocked on workspace hygiene.
func prepareJdtlsWorkspace(dir string) {
_ = os.MkdirAll(dir, 0o755)
_ = os.Remove(filepath.Join(dir, ".metadata", ".lock"))
}