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

Vim integration #1

Open
stapelberg opened this issue Aug 23, 2017 · 7 comments
Open

Vim integration #1

stapelberg opened this issue Aug 23, 2017 · 7 comments

Comments

@stapelberg
Copy link
Owner

No description provided.

@fatih
Copy link

fatih commented Aug 24, 2017

Hi @stapelberg,

Thanks for the tool, this looks great! I really love this tool and was going to work on a similar one, however now that you wrote it there is no need for me (Which is great!).

Can you please update your Readme to include instructions how it's used inside an editor? Does it accept an offset? What does it return? Does it output in JSON?

As an example please check out this section from gomodifgtags: https://github.com/fatih/gomodifytags#editor-integration As you see the tool provides all the necessary primivites so other editors can easily integrate it. Especially a JSON output is crucial for some editors as it's more efficient because we can just replace the necessary lines with it.

I'm more than happy to integrate but first I need all the information available (above questions on how to use it) so we can integrate this into vim-go.

@stapelberg
Copy link
Owner Author

Hey @fatih, thanks for your message!

Currently, the tool accepts a guru-like byte offset into the file, e.g. “myfile.go:#90”. I think that matches gomodifytags’s -offset. See also expanderr_test.go for some examples.

expanderr’s output is the entire file contents, with the specified call expression expanded — this was the most convenient for Emacs integration.

We can totally introduce the JSON output format which you use in gomodifytags. Would you be interested in sending a PR? If not, I can work on it (most likely tomorrow).

@wayneashleyberry
Copy link

This is making me so happy right now 😄

@stapelberg stapelberg self-assigned this Sep 2, 2017
stapelberg added a commit that referenced this issue Sep 2, 2017
@stapelberg
Copy link
Owner Author

I took your silence as “too busy right now” and went ahead creating pull request #3. If that looks good to you, I’ll merge it and you can add support in vim-go…?

@fatih
Copy link

fatih commented Sep 13, 2017

Thanks @stapelberg. Sorry for the late response, I'm quite busy handling the issues on vim-go and my official work. I've opened this fatih/vim-go#1445 so it's known by us (vim-go). I'll add comments to your PR once I've tried it out.

stapelberg added a commit that referenced this issue Dec 11, 2017
@fatih
Copy link

fatih commented Dec 28, 2017

I've just looked into this and think this needs some improvements until it's ready. Some of the things are:

  • For example suppose you have this code:
func foo() error {
	bar()

	// no return yet as I'm still developting this
}

func bar() error {
	return errors.New("foo")
}

When I put my cursor on top of bar() and call :GoExpandErr it returns an error saying:

2017/12/28 17:58:43 ignoring type-checking error: demo.go:54:1: missing return
{"start":51,"end":51,"lines":["\tif err := bar(); err != nil {","\t\treturn err","\t}"]}

It actually returns something. However this is wrong. The error should be part of json and we should be able to decide whether we can change the buffer or not. I think the error message above can be mitigated, but not sure how expanderr implemented it.

  • Suppose you have this piece of code:
func foo() {
	// I want to panic here
	bar()

}

func bar() error {
	return errors.New("foo")
}

When I call :GoExpandErr when my cursor is on bar()~ inside foo()` I got this error:

2017/12/28 18:04:49 current function returns no values, cannot return error

I think if there are no returns, it should default to panic(err.Error()) or something alike.

@stapelberg
Copy link
Owner Author

I created issue #14 and #15 to track these suggestions. Help welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants