microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 648 forks source link

Cursor jumps to top of file on format on save. #3176

Closed GAZ082 closed 4 years ago

GAZ082 commented 4 years ago

This is exact duplicate of: #1389

"[go]": {
    "editor.formatOnSave": false,

Is a workaround. This is affecting go files only.

Version: 1.44.0 (user setup) Commit: 2aae1f26c72891c399f860409176fe435a154b13 Date: 2020-04-07T23:31:18.860Z Electron: 7.1.11 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 10.0.19041

stamblerre commented 4 years ago

Can you share your full VS Code settings? Are you using the language server?

GAZ082 commented 4 years ago

Hi, yes, I'm using gopls.

{
  "sync.gist": "xxx",
  "sync.autoUpload": false,
  "sync.forceDownload": false,
  "sync.quietSync": false,
  "sync.removeExtensions": true,
  "sync.syncExtensions": true,
  "editor.fontFamily": "Fira Code",
  "editor.fontLigatures": true,
  "editor.formatOnType": true,
  "explorer.confirmDragAndDrop": false,
  "files.autoSave": "afterDelay",
  "explorer.confirmDelete": false,
  "git.enableSmartCommit": true,
  "window.zoomLevel": 0,
  "git.confirmSync": false,
  "workbench.activityBar.visible": true,
  "window.menuBarVisibility": "default",
  "workbench.sideBar.location": "left",
  "terminal.integrated.rendererType": "dom",
  "editor.multiCursorModifier": "ctrlCmd",
  "editor.wordWrap": "wordWrapColumn",
  "editor.snippetSuggestions": "top",
  "files.trimFinalNewlines": true,
  "files.trimTrailingWhitespace": true,
  "editor.foldingStrategy": "indentation",
  "zenMode.hideStatusBar": false,
  "zenMode.hideTabs": false,
  "zenMode.hideActivityBar": false,
  "breadcrumbs.enabled": true,
  "dayNightThemeSwitcher.dayTheme": "Quiet Light",
  "dayNightThemeSwitcher.nightTheme": "SynthWave '84",
  "terminal.explorerKind": "external",
  "editor.hover.delay": 200,
  "editor.minimap.enabled": false,
  "git.autofetch": true,
  "markdown.preview.breaks": true,
  "editor.largeFileOptimizations": false,
  "terminal.external.linuxExec": "mate-terminal",
  "terminal.integrated.shell.windows": "C:\\Windows\\System32\\wsl.exe",
  "sync.autoDownload": false,
  "editor.tabSize": 2,
  "sync.forceUpload": false,
  "diffEditor.renderSideBySide": false,
  "debug.console.fontSize": 12,
  "debug.console.wordWrap": false,
  "go.useLanguageServer": true,
  "go.toolsGopath": "/opt/go",
  "go.testFlags": [
    "-count=1",
    "-v"
  ],
  "go.inferGopath": true,
  "go.toolsEnvVars": {
    "GO111MODULE": "on",
  },
  "go.formatTool": "goimports",
  "go.testTimeout": "30s",
  "go.lintTool": "golangci-lint",
  "go.autocompleteUnimportedPackages": true,
  "[go]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true,
    },
    // Optional: Disable snippets, as they conflict with completion ranking.
    "editor.snippetSuggestions": "inline",
  },
  "[go.mod]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true,
    },
  },
  "window.enableMenuBarMnemonics": false,
  "editor.suggestSelection": "first",
  "diffEditor.ignoreTrimWhitespace": false,
  "editor.fontSize": 14,
  "workbench.statusBar.visible": true,
  "bookmarks.navigateThroughAllFiles": true,
  "bookmarks.saveBookmarksInProject": true,
  "workbench.colorCustomizations": {
    "editor.lineHighlightBackground": "#00000022",
  },
  "workbench.colorTheme": "Quiet Light",
  "telemetry.enableCrashReporter": false,
  "telemetry.enableTelemetry": false,
  "update.mode": "start",
  "editor.renderWhitespace": "none",
}
stamblerre commented 4 years ago

This sounds like a bug that existed in older versions of gopls. Can you confirm that you are using v0.4.0 (gopls version)? Otherwise, can you share the gopls logs you see after formatting a file? Information on how to capture detailed gopls logs can be found here.

GAZ082 commented 4 years ago

Updated Go tools and looks like the problem was fixed. Will close the issue and report back if happens again. Thanks!