From dd92cbbe71b91db0d5c66611f7098c7c2da7271a Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Fri, 5 Apr 2024 20:26:32 +0530 Subject: [PATCH 1/6] Show ident name on hover if type not found --- internal/lsp/hover.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/lsp/hover.go b/internal/lsp/hover.go index bc49f2b..e9726a1 100644 --- a/internal/lsp/hover.go +++ b/internal/lsp/hover.go @@ -85,7 +85,16 @@ func (s *server) Hover(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2 case *ast.SelectorExpr: return hoverSelectorExpr(ctx, s, reply, params, pgf, pkg, paths, n, t, int(line)) default: - return reply(ctx, nil, nil) + return reply(ctx, protocol.Hover{ + Contents: protocol.MarkupContent{ + Kind: protocol.Markdown, + Value: FormatHoverContent(n.Name, ""), + }, + Range: posToRange( + int(params.Position.Line), + []int{int(n.Pos()), int(n.End())}, + ), + }, nil) } } typeStr := tv.Type.String() From 09368a0b0ac8655244ee29b6f3a23bfc045d0054 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sun, 14 Apr 2024 22:23:34 +0530 Subject: [PATCH 2/6] chore: remove unnecessary logs --- internal/lsp/completion.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index f40bc7b..1a4b791 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -244,7 +244,6 @@ func (s *server) Completion(ctx context.Context, reply jsonrpc2.Replier, req jso break } t := parseType(typeStr, path) - slog.Info(t) methods, ok := pkg.Methods.Get(t) if !ok { break @@ -304,7 +303,6 @@ func (s *server) Completion(ctx context.Context, reply jsonrpc2.Replier, req jso break } t := parseType(typeStr, path) - slog.Info(t) methods, ok := pkg.Methods.Get(t) if !ok { break From eb21e08629a91881226cea1c95c85ffac1584fd3 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Apr 2024 16:57:25 +0530 Subject: [PATCH 3/6] Parse from snapshot instead of disk --- internal/lsp/completion.go | 17 ++++++++++------- internal/lsp/snapshot.go | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index 1a4b791..c1f0ff0 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -164,7 +164,7 @@ func (s *server) Completion(ctx context.Context, reply jsonrpc2.Replier, req jso return reply(ctx, nil, errors.New("snapshot not found")) } // Try parsing current file - pgf, err := file.ParseGno(ctx) + pgf, err := file.ParseGno2(ctx) if err != nil { return reply(ctx, nil, errors.New("cannot parse gno file")) } @@ -180,12 +180,6 @@ func (s *server) Completion(ctx context.Context, reply jsonrpc2.Replier, req jso } } - // Load pkg from cache - pkg, ok := s.cache.pkgs.Get(filepath.Dir(string(uri.Filename()))) - if !ok { - return reply(ctx, nil, nil) - } - // Completion is based on what precedes the cursor. // Find the path to the position before pos. paths, _ := astutil.PathEnclosingInterval(pgf.File, token.Pos(offset-1), token.Pos(offset-1)) @@ -193,6 +187,15 @@ func (s *server) Completion(ctx context.Context, reply jsonrpc2.Replier, req jso return reply(ctx, nil, nil) } + // Debug + // slog.Info("COMPLETION", "token", fmt.Sprintf("%s", paths[0])) + + // Load pkg from cache + pkg, ok := s.cache.pkgs.Get(filepath.Dir(string(uri.Filename()))) + if !ok { + return reply(ctx, nil, nil) + } + switch n := paths[0].(type) { case *ast.Ident: _, tv := getTypeAndValue( diff --git a/internal/lsp/snapshot.go b/internal/lsp/snapshot.go index b867a7a..f197e13 100644 --- a/internal/lsp/snapshot.go +++ b/internal/lsp/snapshot.go @@ -46,6 +46,7 @@ type ParsedGnoFile struct { Src []byte } +// ParseGno reads src from disk and parse it func (f *GnoFile) ParseGno(ctx context.Context) (*ParsedGnoFile, error) { fset := token.NewFileSet() ast, err := parser.ParseFile(fset, f.URI.Filename(), nil, parser.ParseComments) @@ -64,6 +65,27 @@ func (f *GnoFile) ParseGno(ctx context.Context) (*ParsedGnoFile, error) { return pgf, nil } +// ParseGno2 parses src from GnoFile instead of reading from disk +// Right now it's only used in `completion.go` +// TODO: Replace content of `ParseGno` with `ParseGno2` +func (f *GnoFile) ParseGno2(ctx context.Context) (*ParsedGnoFile, error) { + fset := token.NewFileSet() + ast, err := parser.ParseFile(fset, f.URI.Filename(), f.Src, parser.ParseComments) + if err != nil { + return nil, err + } + + pgf := &ParsedGnoFile{ + URI: f.URI, + + File: ast, + Fset: fset, + Src: f.Src, + } + + return pgf, nil +} + // contains parsed gno.mod file. type ParsedGnoMod struct { URI string From ceb978f84461346149ff07fba127d37b7b8cf409 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Apr 2024 17:08:19 +0530 Subject: [PATCH 4/6] Create go.yml --- .github/workflows/go.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..ce4281b --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,25 @@ +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.21 + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... From eeeb3d908dce063fca36b23fd41b6034afc6112f Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 15 Apr 2024 17:08:31 +0530 Subject: [PATCH 5/6] Add workflow status badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4201673..35702c8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # `gnopls`, the Gno language server +![Build & Test](https://github.com/harry-hov/gnopls/actions/workflows/go.yml/badge.svg) + `gnopls` (pronounced "Gno please") is the unofficial Gno [language server]. It provides IDE features to any [LSP]-compatible editor. ## Installation From 0db9757f087272318f37656c179b69cc9b4cb06a Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Wed, 29 May 2024 18:20:44 +0530 Subject: [PATCH 6/6] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 35702c8..570dfac 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +*Note: `harry-hov/gnopls` is now [`gnolang/gnopls`](https://github.com/gnolang/gnopls) + # `gnopls`, the Gno language server ![Build & Test](https://github.com/harry-hov/gnopls/actions/workflows/go.yml/badge.svg)