Skip to content

Commit 7cfa28c

Browse files
committed
Add lsp cge command
1 parent 731fe22 commit 7cfa28c

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ Download and execute the correct version of [cg-gen-events](https://github.com/c
116116
codegame gen-events <input>
117117
```
118118

119+
### LSP
120+
121+
#### CGE
122+
123+
Download and execute the correct version of [cge-ls](https://github.com/code-game-project/cg-gen-events/tree/main/cmd/cge-ls):
124+
```
125+
codegame lsp cge
126+
```
127+
119128
### cg-debug
120129

121130
Download and execute the correct version of [cg-debug](https://github.com/code-game-project/cg-debug):

cmd/genEvents.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ var genEventsCmd = &cobra.Command{
4242
if data.Type == "client" {
4343
abort(errors.New("Use `codegame update` instead."))
4444
} else if data.Type != "server" {
45-
fmt.Println("hi")
4645
abort(errors.New("Expected game URL."))
4746
} else {
4847
filename = filepath.Join(root, "events.cge")
@@ -52,9 +51,10 @@ var genEventsCmd = &cobra.Command{
5251
output = filepath.Join(root, strings.ReplaceAll(strings.ReplaceAll(data.Game, "_", ""), "-", ""))
5352
default:
5453
abort(errors.New("Expected game URL."))
55-
fmt.Println("hi2")
5654
}
5755
}
56+
} else {
57+
filename = args[0]
5858
}
5959

6060
var cge []byte

cmd/lsp.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
// lspCmd represents the lsp command
8+
var lspCmd = &cobra.Command{
9+
Use: "lsp",
10+
Short: "Launch a language server.",
11+
}
12+
13+
func init() {
14+
rootCmd.AddCommand(lspCmd)
15+
}

cmd/lsp_cge.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
8+
"github.com/adrg/xdg"
9+
"github.com/code-game-project/go-utils/exec"
10+
"github.com/code-game-project/go-utils/external"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var cgLSPCGEPath = filepath.Join(xdg.DataHome, "codegame", "bin", "lsp", "cge")
15+
16+
// cgeCmd represents the cge command
17+
var cgeCmd = &cobra.Command{
18+
Use: "cge",
19+
Short: "Launch cge-ls.",
20+
Args: cobra.ArbitraryArgs,
21+
Run: func(_ *cobra.Command, args []string) {
22+
version, err := external.LatestGithubTag("code-game-project", "cg-gen-events")
23+
abort(err)
24+
version = strings.TrimPrefix(version, "v")
25+
26+
exeName, err := external.InstallProgram("cge-ls", "cge-ls", "https://github.com/code-game-project/cg-gen-events", version, cgLSPCGEPath)
27+
abort(err)
28+
29+
_, err = exec.Execute(false, filepath.Join(cgLSPCGEPath, exeName), args...)
30+
if err != nil {
31+
os.Exit(1)
32+
}
33+
},
34+
}
35+
36+
func init() {
37+
lspCmd.AddCommand(cgeCmd)
38+
}

0 commit comments

Comments
 (0)