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

x/tools/gopls: formatting with missing final line break clears last line #33717

Open
carlpett opened this issue Aug 19, 2019 · 11 comments
Open

x/tools/gopls: formatting with missing final line break clears last line #33717

carlpett opened this issue Aug 19, 2019 · 11 comments

Comments

@carlpett
Copy link

@carlpett carlpett commented Aug 19, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.6 linux/amd64

Does this issue reproduce with the latest release?

Yes, of gopls, at least.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/cape/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/cape/dev"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/PATH-TO-MY-MODULE/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build692302619=/tmp/go-build -gno-record-gcc-switches"

Also, running in Sublime with LSP package, if relevant.

What did you do?

Write code. Do not place final empty newline. Format.

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, world")
} // No newline!

What did you expect to see?

Newline added to the end of the file

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, world")
} // Added newline!

What did you see instead?

Last line cleared.

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, world")
@gopherbot gopherbot added this to the Unreleased milestone Aug 19, 2019
@gopherbot gopherbot added the gopls label Aug 19, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 19, 2019

Thank you for filing a gopls issue! Please take a look at the Troubleshooting section of the gopls Wiki page, and make sure that you have provided all of the relevant information here.

@ianthehat

This comment has been minimized.

Copy link

@ianthehat ianthehat commented Aug 19, 2019

This might be an issue with sublime, we have a test specifically for this case that passes, and I cannot reproduce in either VSCode or vim.
Can you try using gopls from the command line with gopls format -w <filename> and see if works normally, if so it is almost definitely a problem with the way sublime applies past end of file edits.

@carlpett

This comment has been minimized.

Copy link
Author

@carlpett carlpett commented Aug 19, 2019

Yep, seems to be the case, commandline works. Is this something which I should report to Sublime or the LSP extension?

@ianthehat

This comment has been minimized.

Copy link

@ianthehat ianthehat commented Aug 19, 2019

Honestly I am not sure, I do not use/run/understand sublime. My guess would be the lsp extension as formatting and the application of edits should be a fundamental feature of lsp integration.
I am going to close this issue, please feel free to comment again if you need it re-opened or if sublime reports there is something we are doing wrong.

@haferburg

This comment has been minimized.

Copy link

@haferburg haferburg commented Aug 21, 2019

@ianthehat Hi there! Please have a look at sublimelsp/LSP#690. We think that the server sends an invalid line number. In this example, the file has lines 0..8, and the server requests are for line 9/column 0.

@stamblerre stamblerre reopened this Aug 24, 2019
@gopherbot gopherbot added the Tools label Sep 12, 2019
@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Nov 4, 2019

It looks like the upstream issue in the Sublime repository has been closed. @haferburg is this still an issue?

@haferburg

This comment has been minimized.

Copy link

@haferburg haferburg commented Nov 7, 2019

@stamblerre stamblerre assigned ianthehat and stamblerre and unassigned stamblerre Nov 7, 2019
@stamblerre stamblerre changed the title x/tools/cmd/gopls: Formatting with missing final line break clears last line x/tools/cmd/gopls: formatting with missing final line break clears last line Nov 7, 2019
@stamblerre stamblerre modified the milestones: Unreleased, gopls v1.0 Dec 4, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 7, 2019

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Dec 7, 2019

My apologies - the WaitingForInfo label should have been removed. I will try to investigate this soon.

@ianlancetaylor ianlancetaylor reopened this Dec 7, 2019
@pjweinbgo

This comment has been minimized.

Copy link
Contributor

@pjweinbgo pjweinbgo commented Jan 27, 2020

Why is this still open? In any case, it shouldn't be blocking 1.0.0

@stamblerre

This comment has been minimized.

Copy link
Contributor

@stamblerre stamblerre commented Jan 28, 2020

I left it open because it seemed to still require investigation (#33717 (comment)). I'm trying to mark all issues that still need investigation as gopls/v1.0.0 to make sure that we at least take a look at them (and maybe decide they aren't actually gopls/v1.0.0).

@stamblerre stamblerre changed the title x/tools/cmd/gopls: formatting with missing final line break clears last line x/tools/gopls: formatting with missing final line break clears last line Jan 30, 2020
@stamblerre stamblerre modified the milestones: gopls/v1.0.0, gopls/v0.4.0 Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.