-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: implement rangeFormatting LSP request #31150
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think I fixed this in https://go-review.googlesource.com/c/tools/+/170186, please re-open if it is still happening. |
I'm still seeing this in 202502a: |
I use vscode-go get same error , when I save a go file,I miss result
And my settings.json "go.alternateTools": {
"go-langserver": "gopls",
},
"go.languageServerExperimentalFeatures": {
"format": true,
"autoComplete": true,
"goToDefinition": true,
"signatureHelp": true,
"goToTypeDefinition": true
},
"go.useLanguageServer": true,
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
} I try
it's not ok T.T |
Can reproduce on Windows 10 64 bit, Go 1.12.4, VSCode 1.33.1 and gopls@cb2dda6eabdf9160e66ca7293897f984154a7f8b (latest at this time). VSCode settings: "go.useLanguageServer": true,
"[go]": {
"editor.snippetSuggestions": "none",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"gopls": {
"usePlaceholders": true,
"enhancedHover": true
}, Edit: I noticed this error is showing up every time I save a Go file. |
I've found a temporary solution: convert all your source files from CRLF to LF (from Windows to Unix line endings). Note for VSCode users: don't forget to put 🍡 Yay! 🍡 Now I'm not seeing the ToUTF16Column error anymore, and gopls formats my source files when it didn't before. Hope this helps some fellow DOSphers. |
@zippoxer the |
pulled the latest 'tools', vscode with gopls is still not working... |
I can confirm that my |
I'm still seeing this despite not having any Windows line endings. Sample stack trace (if I change a
@ianthehat - is the related to the diff changes that landed not long ago? |
I am confused as to what is happening here, and I can't reproduce it. |
Ok, I've managed to track down this particular instance of the Sequence of eventsgopls server start ======================= gopls.Initialize() call; params: &protocol.InitializeParams{ ProcessID: 0, RootPath: "", RootURI: "file:///home/myitcv/gostuff/src/github.com/myitcv/playground", Capabilities: protocol.ClientCapabilities{ Workspace: struct { ApplyEdit bool "json:\"applyEdit,omitempty\""; WorkspaceEdit struct { DocumentChanges bool "json:\"documentChanges,omitempty\""; ResourceOperations []protocol.ResourceOperationKind "json:\"resourceOperations,omitempty\""; FailureHandling protocol.FailureHandlingKind "json:\"failureHandling,omitempty\"" } "json:\"workspaceEdit,omitempty\""; DidChangeConfiguration struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"didChangeConfiguration,omitempty\""; DidChangeWatchedFiles struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"didChangeWatchedFiles,omitempty\""; Symbol struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; SymbolKind struct { ValueSet []protocol.SymbolKind "json:\"valueSet,omitempty\"" } "json:\"symbolKind,omitempty\"" } "json:\"symbol,omitempty\""; ExecuteCommand struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"executeCommand,omitempty\""; WorkspaceFolders bool "json:\"workspaceFolders,omitempty\""; Configuration bool "json:\"configuration,omitempty\"" }{}, TextDocument: struct { Synchronization struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; WillSave bool "json:\"willSave,omitempty\""; WillSaveWaitUntil bool "json:\"willSaveWaitUntil,omitempty\""; DidSave bool "json:\"didSave,omitempty\"" } "json:\"synchronization,omitempty\""; Completion struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; CompletionItem struct { SnippetSupport bool "json:\"snippetSupport,omitempty\""; CommitCharactersSupport bool "json:\"commitCharactersSupport,omitempty\""; DocumentationFormat []protocol.MarkupKind "json:\"documentationFormat,omitempty\""; DeprecatedSupport bool "json:\"deprecatedSupport,omitempty\""; PreselectSupport bool "json:\"preselectSupport,omitempty\"" } "json:\"completionItem,omitempty\""; CompletionItemKind struct { ValueSet []protocol.CompletionItemKind "json:\"valueSet,omitempty\"" } "json:\"completionItemKind,omitempty\""; ContextSupport bool "json:\"contextSupport,omitempty\"" } "json:\"completion,omitempty\""; Hover struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; ContentFormat []protocol.MarkupKind "json:\"contentFormat,omitempty\"" } "json:\"hover,omitempty\""; SignatureHelp struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; SignatureInformation struct { DocumentationFormat []protocol.MarkupKind "json:\"documentationFormat,omitempty\""; ParameterInformation struct { LabelOffsetSupport bool "json:\"labelOffsetSupport,omitempty\"" } "json:\"parameterInformation,omitempty\"" } "json:\"signatureInformation,omitempty\"" } "json:\"signatureHelp,omitempty\""; References struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"references,omitempty\""; DocumentHighlight struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"documentHighlight,omitempty\""; DocumentSymbol struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; SymbolKind struct { ValueSet []protocol.SymbolKind "json:\"valueSet,omitempty\"" } "json:\"symbolKind,omitempty\""; HierarchicalDocumentSymbolSupport bool "json:\"hierarchicalDocumentSymbolSupport,omitempty\"" } "json:\"documentSymbol,omitempty\""; Formatting struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"formatting,omitempty\""; RangeFormatting struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"rangeFormatting,omitempty\""; OnTypeFormatting struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"onTypeFormatting,omitempty\""; Definition struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" } "json:\"definition,omitempty\""; CodeAction struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; CodeActionLiteralSupport struct { CodeActionKind struct { ValueSet []protocol.CodeActionKind "json:\"valueSet\"" } "json:\"codeActionKind\"" } "json:\"codeActionLiteralSupport,omitempty\"" } "json:\"codeAction,omitempty\""; CodeLens struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"codeLens,omitempty\""; DocumentLink struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"documentLink,omitempty\""; Rename struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; PrepareSupport bool "json:\"prepareSupport,omitempty\"" } "json:\"rename,omitempty\""; PublishDiagnostics struct { RelatedInformation bool "json:\"relatedInformation,omitempty\""; TagSupport bool "json:\"tagSupport,omitempty\"" } "json:\"publishDiagnostics,omitempty\""; Implementation struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" } "json:\"implementation,omitempty\""; TypeDefinition struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" } "json:\"typeDefinition,omitempty\""; ColorProvider struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"colorProvider,omitempty\""; FoldingRange struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; RangeLimit float64 "json:\"rangeLimit,omitempty\""; LineFoldingOnly bool "json:\"lineFoldingOnly,omitempty\"" } "json:\"foldingRange,omitempty\""; Declaration struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" } "json:\"declaration,omitempty\""; SelectionRange struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" } "json:\"selectionRange,omitempty\"" }{ Synchronization: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; WillSave bool "json:\"willSave,omitempty\""; WillSaveWaitUntil bool "json:\"willSaveWaitUntil,omitempty\""; DidSave bool "json:\"didSave,omitempty\"" }{}, Completion: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; CompletionItem struct { SnippetSupport bool "json:\"snippetSupport,omitempty\""; CommitCharactersSupport bool "json:\"commitCharactersSupport,omitempty\""; DocumentationFormat []protocol.MarkupKind "json:\"documentationFormat,omitempty\""; DeprecatedSupport bool "json:\"deprecatedSupport,omitempty\""; PreselectSupport bool "json:\"preselectSupport,omitempty\"" } "json:\"completionItem,omitempty\""; CompletionItemKind struct { ValueSet []protocol.CompletionItemKind "json:\"valueSet,omitempty\"" } "json:\"completionItemKind,omitempty\""; ContextSupport bool "json:\"contextSupport,omitempty\"" }{}, Hover: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; ContentFormat []protocol.MarkupKind "json:\"contentFormat,omitempty\"" }{ DynamicRegistration: false, ContentFormat: {"plaintext"}, }, SignatureHelp: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; SignatureInformation struct { DocumentationFormat []protocol.MarkupKind "json:\"documentationFormat,omitempty\""; ParameterInformation struct { LabelOffsetSupport bool "json:\"labelOffsetSupport,omitempty\"" } "json:\"parameterInformation,omitempty\"" } "json:\"signatureInformation,omitempty\"" }{}, References: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, DocumentHighlight: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, DocumentSymbol: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; SymbolKind struct { ValueSet []protocol.SymbolKind "json:\"valueSet,omitempty\"" } "json:\"symbolKind,omitempty\""; HierarchicalDocumentSymbolSupport bool "json:\"hierarchicalDocumentSymbolSupport,omitempty\"" }{}, Formatting: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, RangeFormatting: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, OnTypeFormatting: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, Definition: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" }{}, CodeAction: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; CodeActionLiteralSupport struct { CodeActionKind struct { ValueSet []protocol.CodeActionKind "json:\"valueSet\"" } "json:\"codeActionKind\"" } "json:\"codeActionLiteralSupport,omitempty\"" }{}, CodeLens: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, DocumentLink: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, Rename: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; PrepareSupport bool "json:\"prepareSupport,omitempty\"" }{}, PublishDiagnostics: struct { RelatedInformation bool "json:\"relatedInformation,omitempty\""; TagSupport bool "json:\"tagSupport,omitempty\"" }{}, Implementation: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" }{}, TypeDefinition: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" }{}, ColorProvider: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, FoldingRange: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; RangeLimit float64 "json:\"rangeLimit,omitempty\""; LineFoldingOnly bool "json:\"lineFoldingOnly,omitempty\"" }{}, Declaration: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\""; LinkSupport bool "json:\"linkSupport,omitempty\"" }{}, SelectionRange: struct { DynamicRegistration bool "json:\"dynamicRegistration,omitempty\"" }{}, }, Experimental: nil, }, InitializationOptions: nil, Trace: "", WorkspaceFolders: nil, } gopls server end ======================= gopls server start ======================= gopls.Initialize() return; err: ; res: &protocol.InitializeResult{ Capabilities: protocol.ServerCapabilities{ TextDocumentSync: map[string]interface {}{ "openClose": bool(true), "change": float64(1), }, HoverProvider: true, CompletionProvider: &protocol.CompletionOptions{ TriggerCharacters: {"."}, AllCommitCharacters: nil, ResolveProvider: false, }, SignatureHelpProvider: &protocol.SignatureHelpOptions{ TriggerCharacters: {"(", ","}, }, DefinitionProvider: true, ReferencesProvider: false, DocumentHighlightProvider: true, DocumentSymbolProvider: true, WorkspaceSymbolProvider: false, CodeActionProvider: true, CodeLensProvider: (*protocol.CodeLensOptions)(nil), DocumentFormattingProvider: true, DocumentRangeFormattingProvider: true, DocumentOnTypeFormattingProvider: (*struct { FirstTriggerCharacter string "json:\"firstTriggerCharacter\""; MoreTriggerCharacter []string "json:\"moreTriggerCharacter,omitempty\"" })(nil), RenameProvider: (*protocol.RenameOptions)(nil), DocumentLinkProvider: (*protocol.DocumentLinkOptions)(nil), ExecuteCommandProvider: (*protocol.ExecuteCommandOptions)(nil), Experimental: nil, ImplementationProvider: false, TypeDefinitionProvider: true, Workspace: (*struct { WorkspaceFolders *struct { Supported bool "json:\"supported,omitempty\""; ChangeNotifications string "json:\"changeNotifications,omitempty\"" } "json:\"workspaceFolders,omitempty\"" })(nil), ColorProvider: false, FoldingRangeProvider: false, DeclarationProvider: false, SelectionRangeProvider: false, }, Custom: {}, } gopls server end ======================= gopls server start ======================= gopls.DidOpen() call; params: &protocol.DidOpenTextDocumentParams{ TextDocument: protocol.TextDocumentItem{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/main.go", LanguageID:"", Version:0, Text:"package main\n"}, } gopls server end ======================= gopls server start ======================= gopls.DidOpen() return; err: gopls server end ======================= gopls server start ======================= gopls.DidOpen() call; params: &protocol.DidOpenTextDocumentParams{ TextDocument: protocol.TextDocumentItem{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go", LanguageID:"", Version:0, Text:""}, } gopls server end ======================= gopls server start ======================= gopls.DidOpen() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 1, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "p", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 2, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "pa", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 3, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "pac", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 4, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "pack", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 5, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "packa", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 6, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "packag", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 7, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "package", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 8, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "package ", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 9, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "package m", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 10, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "package ma", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 11, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "package mai", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.DidChange() call; params: &protocol.DidChangeTextDocumentParams{ TextDocument: protocol.VersionedTextDocumentIdentifier{ Version: 12, TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, }, ContentChanges: { { Range: (*protocol.Range)(nil), RangeLength: 0, Text: "package main", }, }, } gopls server end ======================= gopls server start ======================= gopls.DidChange() return; err: gopls server end ======================= gopls server start ======================= gopls.CodeAction() call; params: &protocol.CodeActionParams{ TextDocument: protocol.TextDocumentIdentifier{URI:"file:///home/myitcv/gostuff/src/github.com/myitcv/playground/blah.go"}, Range: protocol.Range{}, Context: protocol.CodeActionContext{}, } gopls server end ======================= which gives rise to the following exception:
If instead of simply writing |
All tests of format-on-save via gofmt and GOVIMGoFmt (remain) skipped pending golang/go#31759 The tests of range-based GOVIMGoImports and GOVIMGoFmt are skipped pending golang/go#31150
All tests of format-on-save via gofmt and GOVIMGoFmt (remain) skipped pending golang/go#31759 The tests of range-based GOVIMGoImports and GOVIMGoFmt are skipped pending golang/go#31150
I had the same issue on a fresh macOS install today (latests Go, VSCode and tools). I was able to resolve the issue by using |
Change https://golang.org/cl/175938 mentions this issue: |
It seems that range formatting has actually not been working for quite some time - temporarily disabling it until we find a good solution. Formatting should still work correctly however. |
This is marked as "help wanted" currently. @findleyr @pjweinb According to the description of the change that disabled this feature https://golang.org/cl/175938 I guess the challenge is in using the diff library. Will the new diff work you were looking into remove one of the road blockers? |
I don't fully understand what was happening, but once the new diff is in, range formatting is a feature we should be able to make work. |
Go programs are formatted by the go/format package, which has two entry points, format.Node() and format.Source(). The former has restricted input and unless the input is the whole file, loses comments. The latter, to simplify, only formats text that could syntactically be the body of a function. That is, formatting the range |
I'm not super familiar with the LSP API itself, but could you conceivably expand the range you're given until you can format it with Source, and then either return that rewrite or (harder) try to work backwards to figure out the changes required to just the portion that was selected? |
I looked at small extensions of the user selection, but that just didn't
add much utility. There's probably something gopls could do, but what,
exactly? That is, there is a sort of specification of what formatting the
whole file does (namely, call format.Node on the ast.FIle), but what should
range formatting do? Without a clear and convincing proposal we (meaning
me) don't know what to try to implement.
…On Wed, Sep 28, 2022 at 11:16 AM Kyle Lemons ***@***.***> wrote:
I'm not super familiar with the LSP API itself, but could you conceivably
expand the range you're given until you can format it with Source, and then
either return that rewrite or (harder) try to work backwards to figure out
the changes required to just the portion that was selected?
—
Reply to this email directly, view it on GitHub
<#31150 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJIAIZ4ZLIB4UY3SHHYH2TWAROL7ANCNFSM4HCLYSNA>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Considering the following
govim
testscript
in which I attempt to range-format line numbers 3-5 (inc) inmain.go
:I get the error:
The params sent were:
What did you expect to see?
No error.
What did you see instead?
The above error.
cc @stamblerre @ianthehat
The text was updated successfully, but these errors were encountered: