-
Notifications
You must be signed in to change notification settings - Fork 25
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
Use $acmeaddr to address the target text #43
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,10 @@ import ( | |
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
||
p9client "github.com/fhs/9fans-go/plan9/client" | ||
"github.com/fhs/acme-lsp/internal/acme" | ||
"github.com/fhs/acme-lsp/internal/golang_org_x_tools/jsonrpc2" | ||
"github.com/fhs/acme-lsp/internal/lsp" | ||
"github.com/fhs/acme-lsp/internal/lsp/acmelsp" | ||
|
@@ -185,12 +187,12 @@ func run(cfg *config.Config, args []string) error { | |
return fmt.Errorf("unknown assist command %q", args[0]) | ||
} | ||
|
||
winid, err := getWinID() | ||
winid, offset, err := getWinID() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rc := acmelsp.NewRemoteCmd(server, winid) | ||
rc := acmelsp.NewRemoteCmd(server, winid, offset) | ||
|
||
// In case the window has unsaved changes (it's dirty), sync changes with LSP server. | ||
err = rc.DidChange(ctx) | ||
|
@@ -230,16 +232,50 @@ func run(cfg *config.Config, args []string) error { | |
return fmt.Errorf("unknown command %q", args[0]) | ||
} | ||
|
||
func getWinID() (int, error) { | ||
func parseAddress(addr string) (file string, offset int, err error) { | ||
split := strings.Split(addr, ":") | ||
file = split[0] | ||
if len(split) > 1 { | ||
split = strings.Split(split[1], ",") | ||
offsetstring := split[len(split)-1] | ||
offsettrim := strings.TrimPrefix(offsetstring, "#") | ||
offset, err = strconv.Atoi(offsettrim) | ||
} | ||
return file, offset, err | ||
} | ||
|
||
func getWinID() (id int, offset int, err error) { | ||
winid, err := getFocusedWinID(filepath.Join(p9client.Namespace(), "acmefocused")) | ||
if err != nil { | ||
return 0, fmt.Errorf("could not get focused window ID: %v", err) | ||
return 0, -1, fmt.Errorf("could not get focused window ID: %v", err) | ||
} | ||
n, err := strconv.Atoi(winid) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to parse $winid: %v", err) | ||
return 0, -1, fmt.Errorf("failed to parse $winid: %v", err) | ||
} | ||
// Now check for a chord command | ||
acmeaddr := os.Getenv("acmeaddr") | ||
if acmeaddr != "" { | ||
if err != nil { | ||
return 0, -1, fmt.Errorf("failed to to parse chord %v: %v", n, err) | ||
} | ||
file, offset, err := parseAddress(string(acmeaddr)) | ||
if err != nil { | ||
return n, -1, nil | ||
} | ||
// Find the file in the index | ||
windows, err := acme.Windows() | ||
if err != nil { | ||
return n, -1, nil | ||
} | ||
for _, w := range windows { | ||
if w.Name == file { | ||
return w.ID, offset, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why we need the offset. Once we have the window id, this program will take care of getting the current selection position in that window. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Xerox. You don't know the window id, just the file name. |
||
} | ||
} | ||
fmt.Println(file, offset) | ||
} | ||
return n, nil | ||
return n, -1, nil | ||
} | ||
|
||
func dirsOrCurrentDir(dirs []string) ([]protocol.WorkspaceFolder, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this condition is true only when you have a wrapper script around
L
that setswinid
to empty. I don't see how $acmeaddr would be non-empty and $winid empty otherwise.We should be checking $acmeaddr before $windid. If $acmeaddr is non-empty, it's a 2-1 cord. Plan 9 acme gets this correct. Plan9port acme has a bug where it sets $acmeaddr but never unsets it (forgetting we don't have
rfork(RFENVG)
in unix).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created plan9port issue: 9fans/plan9port#533
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edwood has the same bug, and I now have a patch to fix edwood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edwood is now patched.