* Add test where current plugins dont get reset when reloading config file
* Reset loaded plugins when reloading configured project and closing project
* Add test for node16 resolution with package json lookup making casing incorrect
* Handle more places where package direcroy is converted to canonical file path
* Add test where module resolution cache is not local and hence doesnt report errors in watch mode
* Ensure module resolution cache is passed through in watch mode
* Remove unnecessary setting of impliedFormat which should anyways be done as part of create source file
* Add test for packge.json changing and modifying implied format
* Distinguish between package.json watch and affecting file location watch
* Pass in failed lookup and affected file locations for source file's implied format
Also stop creating options if we already have them
* Add diagnostic for explaining file's implied format if based on package.json
* Watch implied format dependencies for modules and schedule update on change
* For program if implied node format doesnt match create new source file. Handle implied node format in document registry
Fixes#50086
* Modify tests to show package.json being watched irrespective of folder its in
* Check file path if it can be watched before watching package.json file
* Because we are watching package.json files and failed lookups its safe to invalidate package json entries instead of clearing them out everytime program is created
* Remove todos
* Fix the incorrect merge
* Pickup PackageJsonInfo renames from #50088
* Rename
* Add test when declaration emit has errors and d.ts emit doesnt change which results in incorrect incremental behaviour
* Refactor
* Use declaration diagnostics in the d.ts signature for the file so it can be more accurate for detecting changes to file that could affect other files
Fixes#49527
* Renames and clarifications
* Simplify serialize declaration diagnostics for signature purpose
Do not serialize file name if error is in same file we are emitting. this should avoid having to do file path computation in most cases.
Locations are start and length instead of line and character.
Do not use any indents
* Fix baselines
* Add a simple queue implementation with better performance than `Array.shift`
This lets us clean up the hack introduced in #49581
* Correct typo
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
* add bug repro test
* add test and start fix implementation
* adjust for useAlias preference
* fix existing renaming test
* refactor to get rid of options
* fix named bindings & other imports cases
* fix eslint error
* address cr comments
* hopefully actually fix eslint
* clean up stale baseline
* make API change non-breaking
* add/fix comments
* Tune FAR aggregation
In making the work queue management more intelligible, we centralized the redundancy check at dequeue time. As a result, the queue tends to get very large (~1.6M items for `SyntaxKind` in this repo) and dequeuing via `shift` is too slow to do that many times. This change makes a few tweaks:
1. Use `Project` identity for de-duping and only maintain a set of keys for `loadAncestorProjectTree`
2. Attempt to filter prior to insertion
3. Use `splice` if many consecutive work queue items will be discarded.
On my box, this cuts FAR for `SyntaxKind` in parser.ts from 38 minutes to 20 seconds (we could do better, but effectively decided not to optimize this worst case scenario).
* Prototype TS plugins on web
This prototype allows service plugins to be loaded on web TSServer
Main changes:
- Adds a new host entryPoint called `importServicePlugin` for overriding how plugins can be loaded. This may be async
- Implement `importServicePlugin` for webServer
- The web server plugin implementation looks for a `browser` field in the plugin's `package.json`
- It then uses `import(...)` to load the plugin (the plugin source must be compiled to support being loaded as a module)
* use default export from plugins
This more or less matches how node plugins expect the plugin module to be an init function
* Allow configure plugin requests against any web servers in partial semantic mode
* Addressing some comments
- Use result value instead of try/catch (`ImportPluginResult`)
- Add awaits
- Add logging
* add tsserverWeb to patch in dynamic import
* Remove eval
We should throw instead when dynamic import is not implemented
* Ensure dynamically imported plugins are loaded in the correct order
* Add tests for async service plugin timing
* Update src/server/editorServices.ts
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Partial PR feedback
* Rename tsserverWeb to dynamicImportCompat
* Additional PR feedback
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Port #48978 forward to the revised FAR code
The old regression test didn't catch the corresponding bug in the new code because it hit the fast path where there's only a single project.
* Drop spurious non-null assertion
* Handle the case where the FAR results map is empty
Searching exactly one project does not imply the presence of exactly one references list.
Fixes#49217
* Use emptyArray
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
* fix(47562): Add option to suppress type hint if variable name matches type
* Remove the unnecessary debug code
* Re-run gulp runtests
* Use equateStringsCaseInsensitive to compare strings
* Clean up FAR and RenameLocations
This change had two goals:
1. Make the code easier to understand, primarily by simplifying the callback structure and minimizing side-effects
2. Improve performance by reducing repeated work, both FAR searches of individual projects and default tsconfig searches
This implementation attempts to preserve the merging order found in the original code (someone less relevant in the present state of using syntactic isDefinition).
* Stop enforcing search and aggregation order
...in preparation for implementing isDefinition explicitly.
Also restore convention of referring to `DocumentPosition`s as "locations".
* Introduce LanguageService.updateIsDefinitionOfReferencedSymbols
...to allow use of the checker when computing isDefinition across projects.
* Update baselines
* Tidy diff
* De-dup simplified results
* Baseline cross-project isDefinition results
* Move de-duping upstream to fix Full output
* Add server baseline test to confirm searches are not repeated
* Manually merge #48758
* Update baseline for newer fix to #48963
* Remove Node12, add Node16.
* Accepted baselines.
* Refactor checking for top-level await, give a better error message in CJS files.
* Accepted baselines.
* Stop erroring on JSON module imports in node ESM since they're no longer experimental.
* Accepted baselines.
* More refactoring, do the same checks for for-await loops.
* Accepted baselines.
* Adjust phrasing to permit for-await on CJS error.
* Accepted baselines.
* Accepted baselines.
* Fix lints.
* WIP
* fix cross-project renaming logic
* only use configure if prefix opt is defined
* refactor skipAlias into stopAtAlias
* fix stopAtAlias
* update another stopAtAlias location
* Add failing test
* Block auto-import module specifiers including node_modules path
* Eagerly resolve module specifiers in completions in nodenext so failures can be filtered
* Add completion info flags for telemetry
* Update API baseline
* Update completions baselines
* Fix missed boolean flip
* Fix remaining tests
* Prototype resolving to JS when go-to-def aliases all resolve to ambient declarations
* Add test infrastructure
* Start fleshing out test coverage
* Fix some go-to-def stuff
* Finish lodash test case
* Make go-to-implementation never return ambient results
* Build new functionality into go-to-implementation
* Update baselines
* Two more test cases
* Refine definition searches for unresolved imports
* Revert "Build new functionality into go-to-implementation"
This reverts commit 381799d0f104000c676334c8e08fcdff9ccac896.
* Fix tests
* Revert go-to-implementation changes
* Wow a bunch of code was unnecessary
* Update baselines and go-to-def test
* Fix navigation on symbols that are not aliases but resolve through aliases in chain
* Temporarily replace go-to-def with new command implementation
* Revert "Temporarily replace go-to-def with new command implementation"
This reverts commit 34c6cfdebbb9e2506ea5e6d528d2cb57b2cdeb2e.
* Revert "Wow a bunch of code was unnecessary"
This reverts commit 1cb2ba646c9e80d1ca08b6fc3f6a2219aac44f67.
* Bring back some deleted code needed for a new test case
* Clean up a little
* Rename more stuff
* Update test
* Update API baseline
* Temporarily replace go-to-def with new command implementation
* PR review fixes
* Fix getTopMostDeclarationNamesInFile
* Rename local
* Use hash set
* Remove option from commandLineParser
* Keep noDtsResolution project around
* Handle AuxiliaryProject kind in ScriptInfo getDefaultProject etc.
* Do not run updateGraph in the background for AuxiliaryProject
* Don’t create auxiliary project outside of semantic mode
* No-op on scheduled invalidation
* Add comments to unit test
* Sync compiler options to auxiliary project
* Fix case sensitivity
* Update extensionIsOk with new file extensions
* PR feedback
* Update API baseline
* Mark scheduleInvalidateResolutionsOfFailedLookupLocations internal
* Use same heuristics on property accesses of loosely-resolvable aliases as unresolvable named imports
* Rename command, and no need to return the bound span
* Update API baseline
* Don't report isDefinition unless the starting node is a declaration
* Drop isDefinition everywhere it isn't specifically needed
* Fix tsserver tests
* Update shim comment
* Update baselines
* Add tests for isDefinition
* Update doc comment
* Clear isDefinition from all references if the first one lacks it
* add label details to completion entry
* Use label details for obj literal method completions
* add label details support flag
* add label details support to fourslash
* support both label details and non-label details in object literal method snippets
* CR fixes
* fixes after rebasing
* fix tsserver tests
* skeleton of new feature
* working prototype
* refactor print and format code into its own function
* minor changes; don't support overloads
* have two completion entries
* get rid of accessor support
* add snippet support
* add formatting
* add trailing comma
* add sourcedisplay
* support auto-imports via completion details
* add user preference option and fix ordering of entries
* cleanup
* don't return code actions for no import fixes
* make sortText lower priority for snippets
* get rid of flag
* use optional member sort text
* update baselines
* don't collect method symbols if insert text is not supported
* remove comment
* return undefined if type is not function type
* only slice if needed
* use union reduction; more test cases
* WIP: modify sort text system
* Improve new sort text system
* add signature and union type check
* re-add flag
* fix tests
* rename sort text helper
* fix test and code for union case
* add new flag to protocol type
* fix spaces
* CR: minor fixes
* CR: more fixes
* CR: restructure main flow
* minor fix
* Trace project creation, loading, and updateGraph
* Drop generic event tracing
* Make argument names more consistent
* Trace diagnostics to make steps easier to interpret
* Fill an unexplained gap in updateGraph
* Move updateGraph tracing into base type
* Fill the gaps in updateGraph
* Add moduleDetection compiler flag to allow for changing how modules are parsed
The default setting is 'auto', where JSX containing files under react-jsx and react-jsxdev are
always parsed as modules, and esm-format files under module: node12+ are always parsed as modules,
in addition to the 'legacy' detection mode's conditions for other files. (Declaration files are exempt from
these new conditions)
The 'legacy' mode preserves TS's behavior prior to the introduction of this flag - a file is
parsed as a module if it contains an import, export, or import.meta expression.
In addition, there is a 'force' mode that forces all non-declaration files to be parsed as modules.
(Declaration files are still only modules if they contain a top-level import or export.)
This technically breaks the parser API, but it's kinda-sorta backwards compatible so long
as you don't need the functionality associated with more recent compiler flags.
* Fix post-merge lint
* Rename function
* Update default value documentation
* PR feedback
* Fix lint and typo
They were using the same helpers as FAR and rename, but they actually behave differently. Decoupling them helps avoid some unnecessary work and will make it easier to clean up FAR in the future.
Scoping NavTo results to a single project (rather than, e.g. all loaded projects) makes the behavior more logical and the implementation simpler.
* Add import assertions for type-only imports and import types to change resolver modes
* By popular request, only allow mode assertions on top-level type only imports
* Add specifier options parameter to specifier generation
* Triple-slash reference type directives can override the import mode used for their resolution
They now use the file's default mode by default, rather than always using commonjs. The new arguments to the
reference directive look like:
```ts
///<reference types="pkg" resolution-mode="require" />
```
or
```ts
///<reference types="pkg" resolution-mode="import" />
```
* Omit redundant import modes in emitter
* Add test for #47806
* Add server test for triple-slash reference mode overrides
* Move FileReference mode into helper
* Update tests/cases/conformance/node/nodeModulesTripleSlashReferenceModeOverride3.ts
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Use package.json cache in module specifier generation
* Let AutoImportProviderProject reuse module resolution cache of host project
* Add missing module resolution cache access, add logging to getRootFileNames
* Reuse packageJsonImportFilter
* Only log when the project will be created, update API baseline
* Remove override that could mess up watches
* Have auto-import provider pull in `exports`
* Revert filtering of node_modules relative paths, to do in separate PR
* Do @types and JS prioritization correctly
* Cache entrypoints on PackageJsonInfo
* Add one more test
* Delete unused function
* Fix other tests - dependencies need package.json files
* Do two passes of exports resolution
* Fix missed refactor
* Apply suggestions from code review
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Uncomment rest of test
* Handle array targets
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Use node ipc for TS Server
For #46417
This lets us use Node's built-in ipc for passing messages to/from the typescript server instead of using stdio
* Remove extra parse
* Add extra logging when using node IPC
* Split out to subclass
* Extract common writeMessage method
* Baseline accept