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

Formatting fails after diff #694

Closed
3 tasks done
onelifenyc opened this issue Feb 14, 2018 · 20 comments
Closed
3 tasks done

Formatting fails after diff #694

onelifenyc opened this issue Feb 14, 2018 · 20 comments
Labels

Comments

@onelifenyc
Copy link

onelifenyc commented Feb 14, 2018

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

Opening an issue from discussion in #561

  • Platform: Win
  • Vetur version: 0.11.7
  • VS Code version: 1.20.1

Workspace Settings:

...
 "emmet.syntaxProfiles": { "vue-html": "html" },
  "stylusSupremacy.insertNewLineBetweenSelectors": true,
  "prettier.disableLanguages": ["vue"],
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  // Options for all default formatters
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned"
    }
  }

Problem

Output -> Vue Language Server

[Error - 6:38:15 PM] Request textDocument/formatting failed.
  Message: Request textDocument/formatting failed with message: Cannot read property 'positionAt' of undefined
  Code: -32603 
[Error - 6:38:15 PM] Request textDocument/hover failed.
  Message: Request textDocument/hover failed with message: Cannot read property 'version' of undefined
  Code: -32603 
[Error - 6:38:16 PM] Request textDocument/hover failed.
  Message: Request textDocument/hover failed with message: Cannot read property 'version' of undefined
  Code: -32603 

BEFORE DIFFING
before-diff

AFTER DIFFING (BUG)
after-diff

Reproducible Case

See GIFs

  1. Make a change - Save (if Auto Format on Save) or Right Click > Format Document
  2. Should format fine
  3. Open Diff from the SCM tab
  4. Close Diff
  5. Open edited file and try Right Click > Format Document
  6. Fails to format

emmet expansions also do not work.

@onelifenyc onelifenyc changed the title Formatting fails after diff in vscode Formatting fails after diff Feb 14, 2018
@cannap
Copy link

cannap commented Feb 28, 2018

is this only for the current file or does it also stops working in other files? .js or other .vue files?

@onelifenyc
Copy link
Author

onelifenyc commented Mar 2, 2018

@cannap Only on the current file (any file type .js / .vue / .styl), i.e. if you diff a file and then continue working on that file, formatting and autocomplete and emmet and other features do not work until you restart VSCode (or disable/enable vetur) which is really frustrating as you can imagine. I am surprised nobody else has reported this. I don't dare to diff because of this issue and I am ocd about code formatting.

@octref
Copy link
Member

octref commented Mar 2, 2018

@cannap I cannot repro it on macOS. I'll try Windows.

@octref
Copy link
Member

octref commented Mar 6, 2018

OK I looked closer. We do not have range formatter. You can only format whole file.

@octref octref closed this as completed Mar 6, 2018
@onelifenyc
Copy link
Author

@octref What does that mean ? Maybe there is a misunderstanding. Just because DIFF is opened upon checking in a file, it should not break the formatter after DIFF is closed and I continue working on that file. I have to close VSCode. Restart it. Start my webpack dev server and all that takes few minutes every time I want to diff and see what I've coded ? And why do you close bugs so nonchalantly as if it is not a bug. Just curious. (new to open source/github)

@octref
Copy link
Member

octref commented Mar 6, 2018

Oh sorry, I thought you were trying to format that selection (which Vetur does not support).

It seems you were formatting the whole document indeed. However I cannot reproduce this issue on either macOS or Windows. Does this repro on https://github.com/octref/veturpack?

@octref octref reopened this Mar 6, 2018
@octref octref added need-more-info and removed bug labels Mar 7, 2018
@octref
Copy link
Member

octref commented Mar 7, 2018

And are you using anything like files.association to map Vue file to other file types?

@octref
Copy link
Member

octref commented Aug 10, 2018

The original bug seems to be about formatter not working in diff editor. This seems to have been solved in latest version of VS Code.

@onelifenyc
Copy link
Author

The original bug is that any time the Compare module is used (the diff), all formatting stops working inside and post using the Compare in a regular Editor window. See GIF, I am pressing CTRL S and also tried formatting using the right-click menu.

Using vscode on windows 64bit version: 1.25.1 (no updates available) and it is not fixed.

image

123

@octref
Copy link
Member

octref commented Aug 10, 2018

Hmm...Here is what i have.
Does this bug repro with https://github.com/octref/veturpack?

format

@onelifenyc
Copy link
Author

The bug does not reproduce meaning I have the same exact behavior as your GIF above IF AND ONLY IF I use git like you.

My environment is corporate with TFS 2017 (TFVC). I copied my project's source code to a new location and init-ed a git for it. Made changes in each of the workspaces (git and tfvc) and when using git, formatting kept working in a diff.

I made sure that I made the Workspace VSCode settings was at bare minimum

{
  "editor.formatOnSave": true,
  "tfvc.location": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\TF.exe",
  "tfvc.restrictWorkspace": true
}

It is really hard to tell where exactly this fails but this narrows it down a lot.

P.S. @cannap this bug I am reporting and still seeing only applies to .vue files maybe in older versions of vscode it didn't work across the board so I am sorry for that confusion.

NOTE: It is NOT just during the DIFF that formatting does not work, but ever since a diff until I kill the instance of vscode, formatting does not work.

123

Here is my full set of settings I usually employ in my projects and they don't affect anything - bug or issue exists regardless:

{
  "team.showWelcomeMessage": false,
  "editor.formatOnSave": true,
  "editor.tabSize": 2,
  "editor.quickSuggestions": { "strings": true },
  "prettier.singleQuote": true,
  "prettier.useTabs": true,
  "prettier.semi": false,
  "files.autoSave": "off",
  "window.zoomLevel": 0,
  "workbench.startupEditor": "newUntitledFile",
  "tfvc.location":
    "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer\\TF.exe",
  "tfvc.restrictWorkspace": true,
  "emmet.syntaxProfiles": { "vue-html": "html" },
  "stylusSupremacy.insertNewLineBetweenSelectors": true,
  "prettier.disableLanguages": ["vue"],
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  // Options for all default formatters
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned"
    }
  }
}

@octref
Copy link
Member

octref commented Aug 22, 2018

@onelifenyc I think that might be a problem between TFVC and VS Code's formatting engine.

So, in short, your problem is that if you are using TFVC and have made changes to a file, formatting stops working — correct? Is it only for external formatters (like those provided in an extension), or do they apply to VS Code's own formatters too (html, css)?

I suggest opening an issue at https://github.com/microsoft/vscode. Also it would be great if you can try installing another formatter like Prettier and try formatting a file, to make sure this is a bug for all external formatters.

@onelifenyc
Copy link
Author

Hi -

The issue as I stated is only with .vue files IN and AFTER a DIFF which is what one does before checking in. JS files can be formatted in a diff and after without an issue and so can my .styl files.

That is why I filed the issue here because it is specific to .vue files and/or vetur as the default extension I use for VueJS.

I did install the one you suggested but what do I need to turn off and where. Seems to be a lot of formatters in play:

  • apparently built in VSCode formatter (js-beautify?).
  • vetur uses prettier
  • I use js-beautify-html for the template portion of .vue files (to my understanding at least)
"vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned"
    }
  }

so what to disable and edit in settings to be able to have a good test with the and I need entire .vue file formatted not the js or stylus or vue-html/html?

@octref
Copy link
Member

octref commented Aug 22, 2018

so can my .styl files.

OK. So that's not a VS Code issue.

Can you do a failed format and see if there's any output from Help -> Toggle Developer Tools?

@onelifenyc
Copy link
Author

onelifenyc commented Aug 23, 2018

Basically I have labeled the screenshots as I reproduce the issue:

0 - on startup, there is a TFVC issue but I don't think it is related. I will have to open an issue with them. The result of that error is that it does not show my pending changes in the source control tab of vscode until I do a refresh. It started breaking recently.

1, 2 - open file, format works, close file.

loading app and formatting successfully and closing file console

3, 4 - open diff from source control tab, right click - format document, also CTRL+S, etc. made more changes, no formatting. close the file, opened it in regular edit window, tried formatting, not working.

during and after diff console

full log :

formatting_stops_working_FULL.log

@octref
Copy link
Member

octref commented Aug 27, 2018

Thanks for the info! This helps a lot with isolating the issue.
The problem seems to be that the grammar is in an endless loop.

Can you run code --list-extensions and let me know what extensions do you have installed?

Also, if you disable all other extensions but Vetur, does this happen?

@octref octref reopened this Aug 27, 2018
@onelifenyc
Copy link
Author

4tron.semantic-ui-snippets
christian-kohler.npm-intellisense
dbaeumer.vscode-eslint
ecmel.vscode-html-css
eg2.vscode-npm-script
esbenp.prettier-vscode
formulahendry.auto-rename-tag
HookyQR.beautify
kamikillerto.vscode-colorize
medzhidov.hex-rgba-converter
minhthai.vscode-todo-parser
ms-vscode.csharp
ms-vsts.team
msjsdiag.debugger-for-chrome
octref.vetur
sdras.vue-vscode-snippets
shd101wyy.markdown-preview-enhanced
sysoev.language-stylus
thisismanta.stylus-supremacy

I will try tomorrow. Thanks.

@octref
Copy link
Member

octref commented Aug 27, 2018

Also, the grammar issue might have already been fixed in Insider version: https://code.visualstudio.com/insiders/, which is scheduled to release next week.

image

@onelifenyc
Copy link
Author

This issue still exists!

With the latest version of vscode for windows 1.28.2, the moment I open a diff (new behavior, hence this comment):

The Vue Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.
Source: Vetur (Extension)

When I try to "Format Document" this message comes up:

There is no document formatter for 'vue'-files installed.

Log and Screenshot of Dev Tools attached

image
vetur-failures.log

@octref
Copy link
Member

octref commented May 10, 2019

The problem seems to be that TFVC opens the diff editor with a non-local, read-only resource: https://github.com/microsoft/azure-repos-vscode/blob/b4494021aac42a2542385d981258cfa28d08f9d2/src/tfvc/scm/resource.ts

Which I can't edit (send format result to). You should open an issue for them.

@octref octref closed this as completed May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants