fix: 修复若干问题,添加java lsp

This commit is contained in:
2026-02-15 22:41:24 +08:00
parent eab464060b
commit 00b0d825d8
264 changed files with 1036 additions and 309 deletions

View File

@@ -107,7 +107,7 @@ func NewClient(parent context.Context, cfg Config) (*Client, error) {
cfg.ClientName = "monica-lsp-gateway"
}
cmd := exec.Command(cfg.Command, cfg.Args...)
cmd := exec.Command(filepath.FromSlash(cfg.Command), cfg.Args...)
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, fmt.Errorf("create stdin pipe: %w", err)
@@ -138,7 +138,7 @@ func NewClient(parent context.Context, cfg Config) (*Client, error) {
// 独立协程持续读取 stdout 并分发响应。
go client.readLoop(stdout)
initCtx, cancel := context.WithTimeout(parent, 10*time.Second)
initCtx, cancel := context.WithTimeout(parent, 30*time.Second)
defer cancel()
if err := client.initialize(initCtx, cfg.RootPath); err != nil {
@@ -277,7 +277,20 @@ func (c *Client) Completion(ctx context.Context, uri string, line, character int
var windowsDrivePattern = regexp.MustCompile(`^[A-Za-z]:`)
// normalizeURI 将相对 file URI 重写为工作区绝对路径 URI
// languageExtensions 定义 languageId 对应的规范文件扩展名
var languageExtensions = map[string]string{
"java": ".java",
"go": ".go",
"javascript": ".js",
"typescript": ".ts",
"python": ".py",
"c": ".c",
"cpp": ".cpp",
"rust": ".rs",
}
// normalizeURI 将相对 file URI 重写为工作区绝对路径 URI
// 并将不匹配 languageId 的扩展名(如 .txt替换为语言对应扩展名。
func (c *Client) normalizeURI(rawURI string) (string, error) {
if rawURI == "" {
return "", errors.New("empty uri")
@@ -305,6 +318,14 @@ func (c *Client) normalizeURI(rawURI string) (string, error) {
localPath = filepath.Join(c.workspaceDir, filepath.FromSlash(rel))
}
// 若文件扩展名与 languageId 不匹配(如 .txt替换为语言对应扩展名。
if expectedExt, ok := languageExtensions[strings.ToLower(c.languageID)]; ok {
currentExt := strings.ToLower(filepath.Ext(localPath))
if currentExt != expectedExt {
localPath = strings.TrimSuffix(localPath, filepath.Ext(localPath)) + expectedExt
}
}
return pathToURI(localPath)
}