Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display Lrefs in dedicated Acme window #74

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cmd/L/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ attempt to find the focused window ID by connecting to acmefocused

List of sub-commands:

comp [-e]
comp [-e] [-E]
Print candidate completions at the cursor position. If
-e (edit) flag is given and there is only one candidate,
the completion is applied instead of being printed.
the completion is applied instead of being printed. If
-E (Edit) flag is given, the first matching candidate is
applied, and all matches will be displayed in a dedicated
Acme window named /LSP/Completions.

def [-p]
Find where the symbol at the cursor position is defined
Expand All @@ -35,9 +38,10 @@ List of sub-commands:
impls
List implementation location(s) of the symbol under the cursor.

refs
refs [-show]
List locations where the symbol under the cursor is used
("references").
("references"). If -show flag is given, all references are displayed
in a dedicated Acme window named /LSP/References (with absolute paths)

rn <newname>
Rename the symbol under the cursor to newname.
Expand Down Expand Up @@ -75,11 +79,11 @@ List of sub-commands:
Current working directory is removed if no directory is specified.

-acme.addr string
address where acme is serving 9P file system (default "/tmp/ns.fhs.:0/acme")
address where acme is serving 9P file system (default "/tmp/ns.username.:0/acme")
-acme.net string
network where acme is serving 9P file system (default "unix")
-proxy.addr string
address used for communication between acme-lsp and L (default "/tmp/ns.fhs.:0/acme-lsp.rpc")
address used for communication between acme-lsp and L (default "/tmp/ns.username.:0/acme-lsp.rpc")
-proxy.net string
network used for communication between acme-lsp and L (default "unix")
-showconfig
Expand Down
12 changes: 7 additions & 5 deletions cmd/L/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"os"
Expand Down Expand Up @@ -63,9 +63,10 @@ List of sub-commands:
impls
List implementation location(s) of the symbol under the cursor.

refs
refs [-show]
List locations where the symbol under the cursor is used
("references").
("references"). If -show flag is given, all references are displayed
in a dedicated Acme window named /LSP/References (with absolute paths)

rn <newname>
Rename the symbol under the cursor to newname.
Expand Down Expand Up @@ -231,7 +232,8 @@ func run(cfg *config.Config, args []string) error {
case "impls":
return rc.Implementation(ctx, true)
case "refs":
return rc.References(ctx)
args = args[1:]
return rc.References(ctx, len(args) > 0 && args[0] == "-show")
case "rn":
args = args[1:]
if len(args) < 1 {
Expand Down Expand Up @@ -280,7 +282,7 @@ func getFocusedWinID(addr string) (string, error) {
return "", fmt.Errorf("$winid is empty and could not dial acmefocused: %v", err)
}
defer conn.Close()
b, err := ioutil.ReadAll(conn)
b, err := io.ReadAll(conn)
if err != nil {
return "", fmt.Errorf("$winid is empty and could not read acmefocused: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/L/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -38,7 +37,7 @@ func TestGetFocusedWinIDFromServer(t *testing.T) {
os.Unsetenv("winid")
want := "321"

dir, err := ioutil.TempDir("", "acmefocused")
dir, err := os.MkdirTemp("", "acmefocused")
if err != nil {
t.Fatalf("couldn't create temporary directory: %v", err)
}
Expand Down
18 changes: 14 additions & 4 deletions cmd/Lone/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,27 @@ List of sub-commands:
be very useful in practice.

-acme.addr string
address where acme is serving 9P file system (default "/tmp/ns.fhs.:0/acme")
address where acme is serving 9P file system (default "/tmp/ns.username.:0/acme")
-acme.net string
network where acme is serving 9P file system (default "unix")
-debug
turn on debugging prints (deprecated: use -v)
-dial value
language server address for filename match (e.g. '\.go$:localhost:4389')
map filename to language server address. The format is
'handlers:host:port'. See -server flag for format of
handlers. (e.g. '\.go$:localhost:4389')
-hidediag
hide diagnostics sent by LSP server
-rootdir string
root directory used for LSP initialization. (default "/")
root directory used for LSP initialization (default "/")
-rpc.trace
print the full rpc trace in lsp inspector format
-server value
language server command for filename match (e.g. '\.go$:gopls')
map filename to language server command. The format is
'handlers:cmd' where cmd is the LSP server command and handlers is
a comma separated list of 'regexp[@lang]'. The regexp matches the
filename and lang is a language identifier. (e.g. '\.go$:gopls' or
'[email protected],[email protected],\.go$@go:gopls')
-showconfig
show configuration values and exit
-v Verbose output
Expand Down
2 changes: 1 addition & 1 deletion cmd/Lone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func run(cfg *config.Config, args []string) error {
case "hov":
err = rc.Hover(ctx)
case "refs":
err = rc.References(ctx)
err = rc.References(ctx, false)
case "rn":
if len(args) < 2 {
usage()
Expand Down
20 changes: 15 additions & 5 deletions cmd/acme-lsp/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,31 @@ be changed by the FormatOnPut and CodeActionsOnPut configuration options.
Usage: acme-lsp [flags]

-acme.addr string
address where acme is serving 9P file system (default "/tmp/ns.fhs.:0/acme")
address where acme is serving 9P file system (default "/tmp/ns.username.:0/acme")
-acme.net string
network where acme is serving 9P file system (default "unix")
-debug
turn on debugging prints (deprecated: use -v)
-dial value
language server address for filename match (e.g. '\.go$:localhost:4389')
map filename to language server address. The format is
'handlers:host:port'. See -server flag for format of
handlers. (e.g. '\.go$:localhost:4389')
-hidediag
hide diagnostics sent by LSP server
-proxy.addr string
address used for communication between acme-lsp and L (default "/tmp/ns.fhs.:0/acme-lsp.rpc")
address used for communication between acme-lsp and L (default "/tmp/ns.username.:0/acme-lsp.rpc")
-proxy.net string
network used for communication between acme-lsp and L (default "unix")
-rootdir string
root directory used for LSP initialization. (default "/")
root directory used for LSP initialization (default "/")
-rpc.trace
print the full rpc trace in lsp inspector format
-server value
language server command for filename match (e.g. '\.go$:gopls')
map filename to language server command. The format is
'handlers:cmd' where cmd is the LSP server command and handlers is
a comma separated list of 'regexp[@lang]'. The regexp matches the
filename and lang is a language identifier. (e.g. '\.go$:gopls' or
'[email protected],[email protected],\.go$@go:gopls')
-showconfig
show configuration values and exit
-v Verbose output
Expand Down
6 changes: 3 additions & 3 deletions cmd/acmefocused/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -35,7 +35,7 @@ func TestListenAndServe(t *testing.T) {
t.Skip("skipping on windows because unix domain sockets are not supported")
}

dir, err := ioutil.TempDir("", "acmefocused-test")
dir, err := os.MkdirTemp("", "acmefocused-test")
if err != nil {
t.Fatalf("couldn't create temporary directory: %v", err)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestListenAndServe(t *testing.T) {
continue
}
want := []byte(testWinID + "\n")
got, err := ioutil.ReadAll(conn)
got, err := io.ReadAll(conn)
if err != nil {
t.Errorf("read failed: %v", err)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/acme/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -160,7 +159,7 @@ func Windows() ([]WinInfo, error) {
return nil, err
}
defer index.Close()
data, err := ioutil.ReadAll(index)
data, err := io.ReadAll(index)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -328,7 +327,7 @@ func (w *Win) ReadAll(file string) ([]byte, error) {
if err != nil {
return nil, err
}
return ioutil.ReadAll(f)
return io.ReadAll(f)
}

func (w *Win) ID() int {
Expand Down Expand Up @@ -782,7 +781,7 @@ type EventHandler interface {
Look(arg string) bool
}

func (w *Win) loadText(e *Event, h EventHandler) {
func (w *Win) loadText(e *Event, _ EventHandler) {
if len(e.Text) == 0 && e.Q0 < e.Q1 {
w.Addr("#%d,#%d", e.Q0, e.Q1)
data, err := w.ReadAll("xdata")
Expand Down
20 changes: 20 additions & 0 deletions internal/acmeutil/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,23 @@ func Hijack(name string) (*Win, error) {
}
return nil, fmt.Errorf("hijack %q: window not found", name)
}

// NOTE: maybe remove and use FileReadWriter instead
type fileWriter func([]byte) (int, error)

func (wr fileWriter) Write(p []byte) (int, error) {
return wr(p)
}

func (w *Win) fileWriter(name string) io.Writer {
var writer fileWriter
writer = func(p []byte) (n int, err error) {
return w.Write(name, p)
}
return writer
}

// returns io.Writer attached to this windows "body"
func (w *Win) BodyWriter() io.Writer {
return w.fileWriter("body")
}
21 changes: 12 additions & 9 deletions internal/lsp/acmelsp/acmelsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -78,10 +77,17 @@ func getLine(p string, l int) string {
return ""
}

func PrintLocations(w io.Writer, loc []protocol.Location) error {
wd, err := os.Getwd()
if err != nil {
wd = ""
func PrintLocations(w io.Writer, loc []protocol.Location, wds ...string) error {
var wd string
if len(wds) == 0 {
var err error
wd, err = os.Getwd()
if err != nil {
wd = ""
}
} else {
// workaround to pass "", filepath.Rel then uses absolute paths inside lsp.LocationLink
wd = wds[0]
}
sort.Slice(loc, func(i, j int) bool {
a := loc[i]
Expand Down Expand Up @@ -192,7 +198,7 @@ func CodeActionAndFormat(ctx context.Context, server FormatServer, doc *protocol
if err != nil {
return err
}
b, err := ioutil.ReadAll(rd)
b, err := io.ReadAll(rd)
if err != nil {
return err
}
Expand All @@ -206,9 +212,6 @@ func CodeActionAndFormat(ctx context.Context, server FormatServer, doc *protocol
},
},
})
if err != nil {
return err
}
}
}
edits, err := server.Formatting(ctx, &protocol.DocumentFormattingParams{
Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/acmelsp/acmelsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package acmelsp

import (
"flag"
"io/ioutil"
"io"
"reflect"
"regexp"
"strings"
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestParseFlagSet(t *testing.T) {
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
f := flag.NewFlagSet("acme-lsp", flag.ContinueOnError)
f.SetOutput(ioutil.Discard)
f.SetOutput(io.Discard)

cfg := config.Default()
err := cfg.ParseFlags(config.LangServerFlags, f, tc.args)
Expand Down
3 changes: 1 addition & 2 deletions internal/lsp/acmelsp/assist.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"time"
"unicode"
Expand Down Expand Up @@ -145,7 +144,7 @@ func readLeftRight(id int, q0 int) (left, right rune, err error) {
return 0, 0, err
}

b, err := ioutil.ReadAll(w.FileReadWriter("xdata"))
b, err := io.ReadAll(w.FileReadWriter("xdata"))
if err != nil {
return 0, 0, err
}
Expand Down
Loading