项目文件夹

文件
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

52 行
1.8 KiB
Go

package lsp
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"os"
"path/filepath"
"github.com/zzet/gortex/internal/platform"
)
// intelephenseStorageDir returns the per-repo index-cache directory
// intelephense should use, rooted at Gortex's cache home (via
// internal/platform, so XDG_CACHE_HOME overrides win and the path is
// Windows-safe). Without an explicit storagePath intelephense writes its
// index to a default global location outside the isolation every other
// engine artifact honours, and two daemons indexing the same repo path
// would collide there.
func intelephenseStorageDir(repoRoot string) string {
sum := sha256.Sum256([]byte(repoRoot))
hash := hex.EncodeToString(sum[:])[:16]
return filepath.Join(platform.CacheDir(), "intelephense", hash)
}
// intelephenseGlobalStorageDir is the shared, repo-independent cache
// intelephense uses for bundled stubs and cross-repo data.
func intelephenseGlobalStorageDir() string {
return filepath.Join(platform.CacheDir(), "intelephense", "global")
}
// intelephenseInitOptions builds the initializationOptions that pin
// intelephense's index caches inside Gortex's cache home. It is resolved at
// initialize time (not a baked literal) because the path depends on the
// per-user cache root and the indexed repo root. Best-effort MkdirAll so the
// server can open the caches on first launch; errors are non-fatal.
func intelephenseInitOptions(repoRoot string) json.RawMessage {
storage := intelephenseStorageDir(repoRoot)
global := intelephenseGlobalStorageDir()
_ = os.MkdirAll(storage, 0o755)
_ = os.MkdirAll(global, 0o755)
opts := struct {
StoragePath string `json:"storagePath"`
GlobalStoragePath string `json:"globalStoragePath"`
}{StoragePath: storage, GlobalStoragePath: global}
b, err := json.Marshal(opts)
if err != nil {
return nil
}
return json.RawMessage(b)
}