|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | +) |
| 8 | + |
| 9 | +func init() { |
| 10 | + // rootCmd.AddCommand(lspCmd) |
| 11 | + lspCmd.AddCommand(lspStdioCmd) |
| 12 | + lspCmd.AddCommand(lspSocketCmd) |
| 13 | + |
| 14 | + lspSocketCmd.Flags().StringVarP( |
| 15 | + &lspSocketAddress, |
| 16 | + "listen", |
| 17 | + "l", |
| 18 | + "127.0.0.1:7998", |
| 19 | + "Address and port on which to listen for LSP connections", |
| 20 | + ) |
| 21 | +} |
| 22 | + |
| 23 | +var lspCmd = &cobra.Command{ |
| 24 | + Use: "lsp", |
| 25 | + Short: "Language Server", |
| 26 | + Long: `Runs the language server for the use inside an editor.`, |
| 27 | + Args: cobra.NoArgs, |
| 28 | + Run: func(cmd *cobra.Command, args []string) { |
| 29 | + lspStdioCmd.Run(lspStdioCmd, args) |
| 30 | + }, |
| 31 | +} |
| 32 | + |
| 33 | +var lspStdioCmd = &cobra.Command{ |
| 34 | + Use: "stdio", |
| 35 | + Aliases: []string{"stdin", "-"}, |
| 36 | + Short: "stdio mode. Supported by most editors.", |
| 37 | + Run: func(cmd *cobra.Command, args []string) { |
| 38 | + fmt.Println("stdio") |
| 39 | + }, |
| 40 | +} |
| 41 | + |
| 42 | +var lspSocketAddress string = "127.0.0.1:7998" |
| 43 | +var lspSocketCmd = &cobra.Command{ |
| 44 | + Use: "socket", |
| 45 | + Short: `opens a socket on the specified address. Make sure the port is free.`, |
| 46 | + Args: cobra.RangeArgs(0, 1), |
| 47 | + Run: func(cmd *cobra.Command, args []string) { |
| 48 | + fmt.Println("socket", lspSocketAddress) |
| 49 | + }, |
| 50 | +} |
0 commit comments