Skip to content

Commit 47d123f

Browse files
committed
give a try with typescript
Signed-off-by: SamYuan1990 <yy19902439@126.com>
1 parent 731ba8d commit 47d123f

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

lang/collect/collect.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
. "github.com/cloudwego/abcoder/lang/lsp"
3030
"github.com/cloudwego/abcoder/lang/python"
3131
"github.com/cloudwego/abcoder/lang/rust"
32+
"github.com/cloudwego/abcoder/lang/typescript"
3233
"github.com/cloudwego/abcoder/lang/uniast"
3334
)
3435

@@ -91,6 +92,8 @@ func switchSpec(l uniast.Language) LanguageSpec {
9192
return cxx.NewCxxSpec()
9293
case uniast.Python:
9394
return python.NewPythonSpec()
95+
case uniast.Typescript:
96+
return typescript.NewTypescriptSpec()
9497
default:
9598
panic(fmt.Sprintf("unsupported language %s", l))
9699
}

lang/lsp/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ func (rwc rwc) Close() error {
219219
// start a LSP process and return its io
220220
func startLSPSever(path string) (io.ReadWriteCloser, error) {
221221
// Launch rust-analyzer
222-
cmd := exec.Command(path)
222+
cmd := exec.Command(path, "--stdio")
223+
cmd.Env = append(os.Environ(), "PATH=/usr/local/bin/:"+os.Getenv("PATH"))
224+
abc, err := exec.LookPath("typescript-language-server")
225+
if err != nil {
226+
fmt.Println("未找到 typescript-language-server 命令:", err)
227+
} else {
228+
fmt.Println("找到 typescript-language-server 命令在:", abc)
229+
}
223230

224231
stdin, err := cmd.StdinPipe()
225232
if err != nil {

lang/parse.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/cloudwego/abcoder/lang/lsp"
3333
"github.com/cloudwego/abcoder/lang/python"
3434
"github.com/cloudwego/abcoder/lang/rust"
35+
"github.com/cloudwego/abcoder/lang/typescript"
3536
"github.com/cloudwego/abcoder/lang/uniast"
3637
)
3738

@@ -109,6 +110,8 @@ func checkRepoPath(repoPath string, language uniast.Language) (openfile string,
109110
openfile, wait = cxx.CheckRepo(repoPath)
110111
case uniast.Python:
111112
openfile, wait = python.CheckRepo(repoPath)
113+
case uniast.Typescript:
114+
openfile, wait = typescript.CheckRepo(repoPath)
112115
default:
113116
openfile = ""
114117
wait = 0
@@ -126,6 +129,8 @@ func checkLSP(language uniast.Language, lspPath string) (l uniast.Language, s st
126129
l, s = cxx.GetDefaultLSP()
127130
case uniast.Python:
128131
l, s = python.GetDefaultLSP()
132+
case uniast.Typescript:
133+
l, s = typescript.GetDefaultLSP()
129134
case uniast.Golang:
130135
l = uniast.Golang
131136
s = ""

lang/uniast/ast.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ import (
2727
type Language string
2828

2929
const (
30-
Golang Language = "go"
31-
Rust Language = "rust"
32-
Cxx Language = "cxx"
33-
Python Language = "python"
34-
Unknown Language = ""
30+
Golang Language = "go"
31+
Rust Language = "rust"
32+
Cxx Language = "cxx"
33+
Python Language = "python"
34+
Typescript Language = "typescript"
35+
Unknown Language = ""
3536
)
3637

3738
func (l Language) String() string {
@@ -44,6 +45,8 @@ func (l Language) String() string {
4445
return "cxx"
4546
case Python:
4647
return "python"
48+
case Typescript:
49+
return "typescript"
4750
default:
4851
return string(l)
4952
}
@@ -64,6 +67,8 @@ func NewLanguage(lang string) (l Language) {
6467
return Cxx
6568
case "python":
6669
return Python
70+
case "typescript":
71+
return Typescript
6772
default:
6873
return Unknown
6974
}

0 commit comments

Comments
 (0)