Skip to content

formatting does not work for newly created JavaScript file #9610

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

Closed
dbaeumer opened this issue Jul 11, 2016 · 9 comments
Closed

formatting does not work for newly created JavaScript file #9610

dbaeumer opened this issue Jul 11, 2016 · 9 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@dbaeumer
Copy link
Member

From @misaxi on July 7, 2016 11:49

  • VSCode Version: 1.2.1
  • OS Version: Win/Mac

Steps to Reproduce:

  1. open VSCode with project folder
  2. create new file, with some code
  3. format code via shortcut or command
  4. nothing happens
  5. switch to previous created file and change some thing
  6. it works

Copied from original issue: microsoft/vscode#8833

@dbaeumer
Copy link
Member Author

Works for me. See Attachement. Do you have any additional steps?

cast

@dbaeumer
Copy link
Member Author

From @misaxi on July 10, 2016 12:16

@dbaeumer I don't know if you are using a beta version. My VSCode icon is in blue :)

But I've upload my gif to show what exactly happened.

Highlights

  • open a folder with files. Code formatting works.
  • create a new file, formatting does not work.
  • close folder, and reopen the folder, it works again.

2016-07-10_22-14-57

@dbaeumer
Copy link
Member Author

Thanks for the steps. The difference to what I do is I create the new file in the explorer whereas you create a new empty file and then save. Need to see what differences in code paths that results in.

@dbaeumer
Copy link
Member Author

The error occurs in the tsserver. The trace is:

Sending request: format (197). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/javascript/abc.js",
    "line": 1,
    "offset": 1,
    "endLine": 1,
    "endOffset": 60
}

Response received: format (197). Request took 3 ms. Success: false . Message: Error processing request. Cannot read property 'lineNumberToInfo' of undefined

@dbaeumer
Copy link
Member Author

Some more tracing. This only happens if there is already a js in the workspace. If a first js file is created that way, no problem occurs. The full trace from the open of the test.js file for which formatting fails is:

Sending request: open (3). Response expected: no. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "fileContent": ""
}

Sending request: change (4). Response expected: no. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "line": 1,
    "offset": 1,
    "endLine": 1,
    "endOffset": 1,
    "insertString": ""
}

Sending request: geterr (5). Response expected: no. Current queue length: 0
Arguments: {
    "delay": 0,
    "files": [
        "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
        "p:/mseng/VSCode/Playgrounds/bugs/8833/abc.js"
    ]
}

Event received: syntaxDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "diagnostics": []
}

Event received: semanticDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "diagnostics": []
}

Event received: syntaxDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/abc.js",
    "diagnostics": []
}

Event received: semanticDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/abc.js",
    "diagnostics": []
}

Sending request: projectInfo (6). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "needFileNameList": true
}

Response received: projectInfo (6). Request took 4 ms. Success: true 
Result: {
    "fileNames": [
        "p:/mseng/VSCode/vscode/extensions/typescript/server/typescript/lib/lib.d.ts",
        "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js"
    ]
}

Sending request: change (7). Response expected: no. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "line": 1,
    "offset": 1,
    "endLine": 1,
    "endOffset": 1,
    "insertString": "console.log( \"Hello World \")                   ; // Comment"
}

Sending request: geterr (8). Response expected: no. Current queue length: 0
Arguments: {
    "delay": 0,
    "files": [
        "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
        "p:/mseng/VSCode/Playgrounds/bugs/8833/abc.js"
    ]
}

Event received: syntaxDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "diagnostics": []
}

Event received: semanticDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "diagnostics": []
}

Event received: syntaxDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/abc.js",
    "diagnostics": []
}

Event received: semanticDiag (0).
Data: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/abc.js",
    "diagnostics": []
}

Sending request: configure (9). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "formatOptions": {
        "tabSize": 4,
        "indentSize": 4,
        "convertTabsToSpaces": true,
        "newLineCharacter": "\n",
        "insertSpaceAfterCommaDelimiter": true,
        "insertSpaceAfterSemicolonInForStatements": true,
        "insertSpaceBeforeAndAfterBinaryOperators": true,
        "insertSpaceAfterKeywordsInControlFlowStatements": true,
        "insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
        "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
        "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
        "placeOpenBraceOnNewLineForFunctions": false,
        "placeOpenBraceOnNewLineForControlBlocks": false
    }
}

Response received: configure (9). Request took 5 ms. Success: true 
Sending request: format (10). Response expected: yes. Current queue length: 0
Arguments: {
    "file": "p:/mseng/VSCode/Playgrounds/bugs/8833/test.js",
    "line": 1,
    "offset": 1,
    "endLine": 1,
    "endOffset": 60
}

Response received: format (10). Request took 3 ms. Success: false . Message: Error processing request. Cannot read property 'lineNumberToInfo' of undefined

Moving to the TS team since this looks like a project setup , ScriptVersion problem.

@robsonrosa
Copy link

@dbaeumer Are you using the EditorConfig for VS Code plugin?

@mhegazy I don't think it is a Typescript bug. It seems more a bug from the EditorConfig plugin. Let me explain what I mean.

I've had a similar problem: the intellisense didn't work when I created new files. After some tests, and removing all my plugins, I've realized that the problems stopped. After reinstalling my plugins one by one I could identify the guilty one: EditorConfig for VS Code.

I can reproduce this problem as many times I install and uninstall the plugin. So, after some researches, I found this issue and another one. Last is a EditorConfig's issue and its related with autocomplete/intellisense.

When I've got here and have noticed the exactly same error message (Message: Error processing request. Cannot read property 'lineNumberToInfo' of undefined) I knew these issues should be related. So, again, I reproduce the tests installing and uninstalling the plugin, but, this time, not only checking the autocomplete, but also the formatter.

And guest what? Both problem occurs only when EditorConfig plugin is installed.

Plugin installed:
with-plugin

Plugin uninstalled:
without-plugin

@dbaeumer
Copy link
Member Author

No

@robsonrosa
Copy link

I didn't expect this answer, @dbaeumer. 😕
Do you have any installed plugin? Could you reproduce the bug with no installed plugin?

@zhengbli
Copy link
Contributor

I don't think it is another plugin's problem, as I can repro on a clean installed vscode. Investigating.

@zhengbli zhengbli mentioned this issue Sep 21, 2016
@zhengbli zhengbli added the Fixed A PR has been merged for this issue label Sep 21, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants