Skip to content

Commit

Permalink
Proof of concept LSP (#27)
Browse files Browse the repository at this point in the history
* feat: better cli

* fix: imports and declarations in repl were broken

* Basic highlighting #19

* feat: basic, proof of concept language server #19

* fix: reduce dependencies of cobra

* chore: upgrade dependencies

* feat: trigger on . #19

* chore: link vscode extension
  • Loading branch information
vknabel authored Feb 5, 2022
1 parent b022027 commit 59a9b87
Show file tree
Hide file tree
Showing 92 changed files with 1,877 additions and 76 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 0
},
{
"name": "Write docs",
"type": "go",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- cli: new CLI interface, including, help and version
- fix: imports and declarations in repl were broken
- lsp: basic, proof of concept language server #19

## v0.0.11

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Valentin Knabel
Copyright (c) 2022 Valentin Knabel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Currently Lithia is an early proof of concept. Basic language features exist, bu
- [x] Generated docs for stdlib
- [x] Improved performance [#20](https://github.com/vknabel/lithia/pull/20)
- [x] Stack traces [#20](https://github.com/vknabel/lithia/pull/20)
- [ ] Creating a custom language server
- [x] Creating a custom language server
- [ ] ... with diagnostics
- [ ] ... with syntax highlighting
- [ ] ... with auto completion
Expand Down Expand Up @@ -64,7 +64,9 @@ If you want to give Lithia a try, the easiest way to get started is using Homebr
$ brew install vknabel/lithia/lithia
```

To get syntax highlighting, download and install the latest version of [Syntax Highlighter with Lithia](https://github.com/vknabel/syntax-highlighter/releases) for VS Code.
To get syntax highlighting, use the [Lithia for VS Code extension](https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-lithia).

> Not using Visual Studio Code? Get started with `lithia lsp --help`.
### Docker

Expand Down
43 changes: 38 additions & 5 deletions app/lithia/cmd/lsp.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package cmd

import (
"fmt"
cobra "github.com/muesli/coral"

"github.com/spf13/cobra"
"github.com/vknabel/lithia/langsrv"
)

func init() {
// rootCmd.AddCommand(lspCmd)
rootCmd.AddCommand(lspCmd)
lspCmd.AddCommand(lspStdioCmd)
lspCmd.AddCommand(lspSocketCmd)
lspCmd.AddCommand(lspIPCCmd)
lspCmd.AddCommand(lspTCPCmd)

lspSocketCmd.Flags().StringVarP(
&lspSocketAddress,
Expand All @@ -35,7 +37,22 @@ var lspStdioCmd = &cobra.Command{
Aliases: []string{"stdin", "-"},
Short: "stdio mode. Supported by most editors.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("stdio")
err := langsrv.RunStdio()
if err != nil {
panic(err)
}
},
}

var lspIPCCmd = &cobra.Command{
Use: "ipc",
Short: `opens a nodejs ipc connection.`,
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
err := langsrv.RunIPC()
if err != nil {
panic(err)
}
},
}

Expand All @@ -45,6 +62,22 @@ var lspSocketCmd = &cobra.Command{
Short: `opens a socket on the specified address. Make sure the port is free.`,
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("socket", lspSocketAddress)
err := langsrv.RunSocket(lspSocketAddress)
if err != nil {
panic(err)
}
},
}

var lspTCPAddress string = "127.0.0.1:7998"
var lspTCPCmd = &cobra.Command{
Use: "tcp",
Short: `opens a tcp connection on the specified address. Make sure the port is free.`,
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
err := langsrv.RunSocket(lspSocketAddress)
if err != nil {
panic(err)
}
},
}
6 changes: 3 additions & 3 deletions app/lithia/cmd/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"io"
"os"

"github.com/spf13/cobra"
"github.com/vknabel/go-lithia/reporting"
"github.com/vknabel/go-lithia/runtime"
cobra "github.com/muesli/coral"
"github.com/vknabel/lithia/reporting"
"github.com/vknabel/lithia/runtime"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions app/lithia/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cmd

import (
"github.com/spf13/cobra"
cobra "github.com/muesli/coral"
"github.com/vknabel/lithia/info"
)

func Execute() error {
Expand All @@ -17,7 +18,7 @@ var rootCmd = &cobra.Command{
"all language features contribute to.\n" +
"\n" +
"Lean more at https://github.com/vknabel/lithia",
Version: "0.0.12-next",
Version: info.Version,
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
Expand Down
4 changes: 2 additions & 2 deletions app/lithia/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"path"

"github.com/spf13/cobra"
"github.com/vknabel/go-lithia/runtime"
cobra "github.com/muesli/coral"
"github.com/vknabel/lithia/runtime"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion app/lithia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/vknabel/go-lithia/app/lithia/cmd"
"github.com/vknabel/lithia/app/lithia/cmd"
)

func main() {
Expand Down
4 changes: 4 additions & 0 deletions ast/decl-constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ func MakeDeclConstant(name Identifier, value Expr, source *Source) *DeclConstant
MetaInfo: &MetaDecl{source},
}
}

func (e DeclConstant) ProvidedDocs() *Docs {
return e.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-data.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ func MakeDeclData(name Identifier, source *Source) *DeclData {
func (e *DeclData) AddField(field DeclField) {
e.Fields = append(e.Fields, field)
}

func (decl DeclData) ProvidedDocs() *Docs {
return decl.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-enum-case.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ func MakeDeclEnumCase(name Identifier) *DeclEnumCase {
MetaInfo: &MetaDecl{},
}
}

func (decl DeclEnumCase) ProvidedDocs() *Docs {
return decl.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ func (e DeclEnum) String() string {
}
return declarationClause + "}"
}

func (decl DeclEnum) ProvidedDocs() *Docs {
return decl.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-extern-type.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ func MakeDeclExternType(name Identifier, source *Source) *DeclExternType {
func (e *DeclExternType) AddField(decl DeclField) {
e.Fields[decl.Name] = decl
}

func (decl DeclExternType) ProvidedDocs() *Docs {
return decl.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-field.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ func MakeDeclField(name Identifier, params []DeclParameter, source *Source) *Dec
},
}
}

func (decl DeclField) ProvidedDocs() *Docs {
return decl.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-func.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ func MakeDeclFunc(name Identifier, impl *ExprFunc, source *Source) *DeclFunc {
},
}
}

func (decl DeclFunc) ProvidedDocs() *Docs {
return decl.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ func (e DeclModule) IsExportedDecl() bool {
func MakeDeclModule(internalName Identifier, source *Source) *DeclModule {
return &DeclModule{Name: internalName, MetaInfo: &MetaDecl{source}}
}

func (decl DeclModule) ProvidedDocs() *Docs {
return decl.Docs
}
4 changes: 4 additions & 0 deletions ast/decl-parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ func MakeDeclParameter(name Identifier, source *Source) *DeclParameter {
},
}
}

func (decl DeclParameter) ProvidedDocs() *Docs {
return decl.Docs
}
5 changes: 5 additions & 0 deletions ast/documented.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ast

type Documented interface {
ProvidedDocs() *Docs
}
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module github.com/vknabel/go-lithia
module github.com/vknabel/lithia

go 1.16

require (
github.com/muesli/coral v1.0.0
github.com/petermattis/goid v0.0.0-20220111183729-e033e1e0bdb5 // indirect
github.com/smacker/go-tree-sitter v0.0.0-20211116060328-db7fde9b5e82
github.com/spf13/cobra v1.3.0
github.com/tliron/glsp v0.0.0-20210824162824-d103e5701036
github.com/tliron/kutil v0.1.52
github.com/vknabel/tree-sitter-lithia v0.0.0-20220121161404-ed4529b7c21c
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
)
Loading

0 comments on commit 59a9b87

Please sign in to comment.