Skip to content

Multiple Project Support #910

Closed
Closed
@basarat

Description

@basarat

Note : Leaving this purely as a documentation, and potential idea for exploration by any TypeStrong / community member

How tsconfig.json detection works now.

We have a file/class called Project which basically consolidates all our access to the TypeScript language service (the code).

When you open a .tsx? file in the editor we lookup some tsconfig.json up the directory tree. If we find one we

  • read it
  • convert it to a project
  • for all the files identified as a part of the project we create a hot cache so we share the same project for queries against these files.

(here is the code)

Issues with this

If you have several tsconfig.json files in your project, e.g.:

  • server/tsconfig.json
  • client/tsconfig.json

The tsconfig files also reference some shared files in:

  • src/shared.

If you open a file from server first then all the files referenced (including shared) will point to that server/tsconfig.json. Then even if you update client/tsconfig.json it will have seemingly no effect on any file that the editor opens (as they all already point to server/tsconfig.json).

Potential fixes

Project selector

This is the approach I am taking with http://alm.tools/ . It features a project search/selector : https://github.com/alm-tools/alm/tree/master/docs/features#project-search + ability to provide a project on the command line (-p flag).

It is less magical then what atom-typescript does, but then again atom-typescript was designed to be as quick to start / unobtrusive as possible i.e. you open a ts file and it just works.

alm.tools is designed to be for typescript alone. You need a project file.

Multiple simultaneous projects

This is the approach taken by VSCode / TSServer (that comes with typescript out of the box).

However there are issues with this design too e.g.:

  • autocomplete can end up with duplicates and deduplication needs to happen
  • rename refactoring needs to take place across all the code base / projects.

All of these complex scenarios are being fixed in TSServer by the Microsoft team (:rose:) and if this is the approach that needs to happen I recommend that current code be pulled out and migrate to TSServer. This will result in feature decrease (e.g. dependency view) but might be better in the long term 🌹

Personal opinions

What I did with atom typescript isn't ideal for sure and it would be better if it takes one of the mentioned approaches. Please note that I did this before tsserver was a thing so ¯\_(ツ)_/¯, and because of (again) ambitious plans of https://alm.tools it does something custom (doesn't use tsserver again as I find my work on async support easier personally, also haven't had the time to take a hard look at TSServer) 🌹 ❤️

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions