Skip to content

make "compileOnSave" option of tsconfig.json recognized by vscode #7015

Closed

Description

Currently "compileOnSave" option of tsconfig.json is ignored by the VS Code:

There is no a workaround to this problem. Please consider doing something about bringing it to life.

Activity

  1. dbaeumer commented on May 30, 2016

    @dbaeumer
    Member

    Added a comment to stackoverflow. This is supported right now via a watch task. But I agree that the tsconfig.json option should be supported as well, which has to come from the TS team though.

  2. added
    typescript
    upstream
    on May 30, 2016
  3. dbaeumer commented on May 30, 2016

    @dbaeumer
    Member

    I opened microsoft/TypeScript#8884 since the support has to go there. I will close this issue as upstream.

  4. zpdDG4gta8XKpMCd commented on May 30, 2016

    @zpdDG4gta8XKpMCd
    Author

    the problem with "watch" is that vscode doesn't allow to run the test command while watching typescript, saying there is another command running, so at least with having to run the tests from under vscode "watch" isn't an option

  5. dbaeumer commented on May 30, 2016

    @dbaeumer
    Member

    We have feature request to allow more than one command.

  6. dbaeumer commented on May 30, 2016

    @dbaeumer
    Member

    As said I close this one since it will be addressed in tsserver.

  7. zpdDG4gta8XKpMCd commented on Aug 25, 2016

    @zpdDG4gta8XKpMCd
    Author
  8. styfle commented on Aug 25, 2016

    @styfle

    Dirk Bäumer (@dbaeumer) Now that it is merged in tsserver will it simply work with vscode or will there need to be more work to integrate it?

  9. dbaeumer commented on Aug 26, 2016

    @dbaeumer
    Member

    Steven (@styfle) it should work with VS Code without additional integration effort. But please note that VS Code still ships with 1.8.10 and I think the feature will not make it out of the box into 2.0 either.

  10. mrcrowl commented on Nov 5, 2016

    @mrcrowl

    Dirk Bäumer (@dbaeumer) From what I can see, there is additional integration effort needed to enable compile on save in VSCode for TypeScript. Since v2.0.5, tsserver has supported the new API methods compileOnSaveAffectedFileList and compileOnSaveEmitFile, but they need to be called from the typescript extension. I've done some prelim work on getting this going for myself and would be happy to make a pull request if there was support? (WIP here if you want to have a look: https://github.com/mrcrowl/vscode/tree/master/extensions/typescript)

  11. dbaeumer commented on Nov 7, 2016

    @dbaeumer
    Member

    mrcrowl you are correct that the current implementation in the tsserver does require quite some work in the extensions. I started a discussion with the TS team about this here: microsoft/TypeScript#11526

    The bottom line is that this doesn't belong into the extension since the extension can never implement this in a efficient way (and the TS team agrees on this). Especially since compileOnSave must also do problem checking. Doesn't make to much sense to write a new JS file without telling the user that you now have compile errors in dependent files.

    So I would opt that instead of adding this to the extension your effort is better put into the tsserver to make this work. I started this along time ago here: https://github.com/Microsoft/TypeScript/blob/dbaeumer/9125/src/server/builder.ts and parts of the work made it into 2.0.6. But still no full builder. Their current builder only manages dependencies: https://github.com/Microsoft/TypeScript/blob/master/src/server/builder.ts

  12. Ciantic commented on Dec 6, 2016

    @Ciantic

    Shouldn't this be re-opened if there is more work to be done in VSCode code base? I'm running 2.2.0-dev in stable VSCode, the compile on save does not work with it.

    Edit: Reason this bug would be nice to be open, so one could track when it becomes feasible to use.

    Edit2: Or is this the main bug microsoft/TypeScript#11526 one could track for this feature?

  13. 23 remaining items

  14. mrcrowl commented on Jun 14, 2017

    @mrcrowl

    For anyone still interested in compile-on-save, here's an unofficial .vsix you can manually install in vs code 13.x that replaces the built-in typescript extension, with one that supports the compileOnSave setting in tsconfig.json:
    https://github.com/mrcrowl/vscode/releases/tag/13.10.8

    edit: added "unofficial"

  15. Dashue commented on Jun 15, 2017

    @Dashue

    mrcrowl Dirk Bäumer (@dbaeumer) Installing that would be a hack around right? When is it officially landing in vscode? I'm running on the latest typescript afaik.

  16. mrcrowl commented on Jun 15, 2017

    @mrcrowl

    dbaumer, your comment from May 18 refers to a preview feature in vscode 13.x that simplifies build tasks for TypeScript (see release notes), which is great... but this feature hasn't yet addressed "compileOnSave", right?


    Johan Nilsson (@Dashue), yes, installing this extension is a hack that is not officially supported. Here's a bit of background:

    As I see it, there are two groups of people wanting "compileOnSave":

    • Group 1 just want TypeScript compilation with minimal configuration, for small-to-medium sized projects.

    • Group 2 want performant TypeScript compilation for larger projects (this is the promise of TypeScript, right? "JavaScript that scales")

    Group 1 are well-covered by a combination of tsconfig.json + watch + tasks.json, i.e. file-system watcher that incrementally builds when a file change is detected.

    I'm concerned with Group 2, who are working on larger projects where even the incremental build takes too long to run. Based on Dirk Bäumer (@dbaeumer)'s May 5 comment there is an awareness of this within the TypeScript and vscode teams (...is there an issue for this?)

    In the meantime, my team needed a way to continue fast TypeScript compiles, often for individual files within the context of a large project. Hence, the provided extension which uses existing tsserver apis to achieve a pragmatic compile-on-save behaviour, while we wait for an official solution to materialize.

    The built-in TypeScript extension runs a tsserver instance in the background, which is synchronised with editor changes. In order to take advantage of that same tsserver instance my version of the extension has to replace the built-in TypeScript extension. It's possible a similar result could now be achieved as a typescript server plugin, although I haven't investigated that route yet.

  17. dbaeumer commented on Jun 16, 2017

    @dbaeumer
    Member

    mrcrowl here some issues in the TS land about compile on save and a full builder in the TS server:

    microsoft/TypeScript#9125
    microsoft/TypeScript#11229

    Building a performant incremental builder for large projects is not trivial (as you might have noticed as well). The TS team is still on this but it might be helpful if you start to vote on microsoft/TypeScript#11229

  18. mrcrowl commented on Jun 16, 2017

    @mrcrowl

    Dirk Bäumer (@dbaeumer) would you consider #28912 as an alternative for now?

  19. dbaeumer commented on Jun 19, 2017

    @dbaeumer
    Member

    mrcrowl I think having TS exposing its API is useful regardless of this issue.

  20. josh-sachs commented on Jun 20, 2017

    @josh-sachs

    The vsix provided by mrcrowl does EXACTLY what vscode should do by default.

  21. meriturva commented on Jun 28, 2017

    @meriturva

    Right now TypeScript 2.4 is landed, but i think there is no news about compileOnSave fix on TS Server or language service. Do we have to wait also VSCode new version to have a productive environment? Vsix from mrcrowl is really a good start (thanks again) but i think that we have to expect an official solution. am i wrong?

  22. bkniffler commented on Jul 14, 2017

    @bkniffler

    The best solution for me was using a build task and ONLY compile the saved file:

    // project: .vscode/task.json
    {
      "version": "0.1.0",
      "command": "node",
      "isShellCommand": true,
      "args": ["${workspaceRoot}/.vscode/task.js", "${file}"],
      "showOutput": "silent",
      "problemMatcher": "$tsc"
    }
    // project: .vscode/task.js
    const { spawn } = require('child_process');
    const { resolve } = require('path');
    
    const root = resolve(__dirname, '..');
    const json = require(resolve(root, 'tsconfig.json')).compilerOptions;
    
    const args = [resolve(root, 'node_modules', '.bin', 'tsc')];
    Object.keys(json).forEach(key => {
      args.push(`--${key}`);
      args.push(`${json[key]}`);
    });
    
    spawn(`node`, args.concat(process.argv.slice(2)), {
      detached: true,
      stdio: 'ignore',
    }).unref();
    // keybindings
    {
        "key": "cmd+s", 
        "command": "workbench.action.tasks.build", 
        "when":"editorTextFocus && editorLangId == 'typescript'"
    },{
        "key": "cmd+s", 
        "command": "workbench.action.tasks.build", 
        "when":"editorTextFocus && editorLangId == 'typescriptreact'"
    }

    The script will pick up the tsconfig.json compilerOptions. Only downside is that it will not output any errors whatsoever since the process is detached to allow for parallel executions of the task in case multiple files are saved.

  23. fuyifan commented on Sep 20, 2017

    @fuyifan

    xygahs0801 It works great. Thank you very much.

  24. josh-sachs commented on Sep 20, 2017

    @josh-sachs

    It sucks that this issue has been closed, as it doesn't appear any official support addressing this has been provided. Visual Studio seems to do this out of the box, without the need to run a battery draining background process during development.

  25. carlpaten commented on Sep 26, 2017

    @carlpaten

    Could this issue please be re-opened? It's not exactly resolved.

  26. mjbvz commented on Sep 26, 2017

    @mjbvz
    Contributor

    LilRed This is issue is still being tracked by #973 and #7342

  27. locked and limited conversation to collaborators on Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

typescriptupstream

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions