Commit graph

170 commits

Author SHA1 Message Date
Andrew Branch a301001420
Use correct program when checking for reexports from AutoImportProviderProject (#40843) 2020-09-30 09:32:19 -07:00
Nathan Shively-Sanders e350c357d2
Alias for module.exports.x = x (#40228)
* Alias for `module.exports.x = x`

This fixes #40155 in a surprisingly small amount of code.

* Treat any aliasable expression as an alias

* test internal references to exported class
2020-09-10 11:23:48 -07:00
Andrew Branch 8ffb7f083d
Reprioritize cross-project module specifier suggestions for auto-import (#40253)
* Add test

* Suggest `paths` module specifiers even when a node_modules path was available

* Fix some tests

* Fix remaining tests

* Add comments
2020-09-03 14:00:06 -07:00
Andrew Branch 838a5e6044
Fix call hierarchy item serialization and server tests (#40348) 2020-09-02 11:34:14 -07:00
Andrew Branch ec33814616
Make AutoImportProviderProject work with symlinked monorepos (#39679)
* Hack everything together

* Add test

* Remove realpath from program

* Ensure symlinked directories are directories

* Revert unnecessary change

* Update baselines

* Use host program realpath on AutoImportProviderProject files before program creation

* Which fixes hasRoots() too

* Apply suggestions from code review

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>

* Lint

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-07-22 13:53:30 -07:00
Alexander T 6b493f2048
fix(23871): change insertNodeAfter to replaceNode to avoid extra newlines (#38045) 2020-07-07 12:54:03 -04:00
Andrew Branch 086e00de91
Expand auto-import to all package.json dependencies (#38923)
* Start experiment

* Add logging

* Go back to a single program

* Fix forEachExternalModuleToImportFrom

* Move auxiliary program to language service

* Add logging

* Don’t use resolution cache

* Fix(?) containingProjects for ScriptInfo in auxiliary program

* Fix ScriptInfo project inclusion

* Add test for default project of auto-importable ScriptInfo

* Add fourslash server test

* Don’t create auto import provider inside node_modules

* Add monorepo-like test

* WIP

* Naively ensure autoImportProvider is up to date after package.json change

* Start limiting when auto update provider gets updated

* Respond to changes in node_modules

* Don’t create auto-import provider until a file is open that would use it

e.g., don’t create them during cross-project find-all-refs

* Clean up naming, @internal marking, and fix empty project creation bug

* Drop devDependencies, include peerDependencies

* Add additional compiler options

* Fix interaction with importSuggestionsCache

* Move option to UserPreferences, allow inclusion of devDependencies

* Don’t filter out peerDependencies

* Watch unparseable package.jsons

* But don’t filter packages out due to an invalid package.json

* Update test

* Don’t use autoImportProvider in codefixes where it can never be used (or any refactors)

* Add CompletionEntry property for telemetry

* Add assertion for isPackageJsonImport to fourslash

* Fix missing pushSymbol argument

* Add isPackageJsonImport to tests and API baselines

* Fix unit test

* Host auto import provider in new Project kind

* Fix InferredProject attaching on AutoImportProvider-included files, load eagerly

* Update Public APIs

* Simplify PackageJsonCache host

* Remove unneeded markAsDirty

* Defer project finished event until after AutoImportProvider is created

* Make AutoImportProviderProject always report isOrphan = true

* Close and remove AutoImportProviderProject when host project closes

* Don’t set pendingEnsureProjectForOpenFiles

* Use hasAddedOrRemovedFiles instead of hasNewProgram

* Use host-wide watchOptions for package.json watching

* Add to `printProjects`

* Clean up

* Get autoImportProvider directly from LanguageServiceHost

* Clean up

* Clean up

* Close auto import provider on disableLanguageService

* Move AutoImportProvider preload to project updateGraph

* Clear auto import suggestion cache when provider program changes

* Fix tests

* Revert yet-unneeded change

* Use projectService host for module resolution host

* Don’t re-resolve type directives if nothing has changed

* Update src/server/project.ts

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>

* Use ts.emptyArray

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-06-22 16:34:27 -07:00
Wesley Wigham 78a99241d8
Reuse input type nodes when serializing signature parameter and return types (#37444)
* Accept change

* Accept the huge set of ever so slightly changed baselines

* Update return type logic to only reuse nodes if original nodes share scope with current node, like property types, only reuse nodes if symbols referened are acessible, reuse nodes for property signatures, too

* Only reuse nodes when a context is provided (otherwise identifier printback may fail)

* Only track symbol if symbol is found and no error is recorded

* Fix type parameter reuse lookup

* Forbid cjs module.exports references in retained nodes

* Adjust check for cjs export references to not include bad module type in output

* Add symbol to all identifiers we see in existing nodes for quickinfo

* Accept fourslash baseline updates

* Accept slightly updated baseline post-merge

* Do not copy original nodes for error types, replace empty type references with any
2020-04-01 19:50:21 -07:00
Jesse Trinity ef377d5a66
Don't delete comments when deleting unused declarations (#37467)
* don't delete comment on variable declaration

* add more declaration kinds

* don't copy comment in convertes6 class

* don't copy comments in convertToES6Class

* add tests

* use isAnyImportSyntax

* handle mixed comment types

* update tests
2020-03-31 10:18:06 -07:00
Wesley Wigham c6c2c4c8d5
Hoist initial assignment to exported names in cjs to they are not blocked by bindings made by __exportStar (#37093)
* Hoist initial assignment to exported names in cjs to they are not blocked by bindings made by __exportStar

* Copy hoisted identifiers so they do not create sourcemaps

* Accept updated baselines
2020-02-28 13:25:28 -08:00
Orta 8a797cad2b
Adds floating block comments to the outlining spans response (#36880)
* Adds floating block comments to the outlining spans response

* Only use one route for grabbing outline nodes, which now includes special casing the EOF token
2020-02-25 17:09:16 -05:00
Andrew Branch f050750cc6
Don’t auto-import undefined (#35504) 2019-12-05 14:47:51 -08:00
Daniel Rosenwasser 3da85df511
Clean up error messages for using TypeScript syntax in JavaScr… (#35254)
* Fix up quotation marks in error messages in JavaScript files.

* Accepted baselines.

* Typescript -> TypeScript

* Accepted baselines.

* Migrate syntactic diagnostics tests to baselining tests.

* Accepted baselines.

* Update diagnosticMessages.json

* Removed markers.

* Add ability to baseline both semantic and syntactic diagnostics.

* Fix up broken diagnostics when using a server LS.

* Accepted baselines.

* Lints.

* Fake up sourcefile objects in the tsserver session client instead.

* Fewer allocations.
2019-11-22 14:51:22 -08:00
Sheetal Nandi 47ec514cf4
Use empty object for invalid package json contents instead of undefined (#34906)
* Use empty object for invalid package json contents instead of undefined
Fixes #34726

* Behave as if package json doesnt exist in case of invalid json in package json
2019-11-04 14:31:45 -08:00
Andrew Branch 304fcee09b
Updated: Only auto-import from package.json (#32517)
* Move package.json related utils to utilities

* Add failing test

* Make first test pass

* Don’t filter when there’s no package.json, fix scoped package imports

* Use type acquisition as a heuristic for whether a JS project is using node core

* Make same fix in getCompletionDetails

* Fix re-exporting

* Change JS node core module heuristic to same-file utilization

* Remove unused method

* Remove other unused method

* Remove unused triple-slash ref

* Update comment

* Refactor findAlias to forEachAlias to reduce iterations

* Really fix re-exporting

* Use getModuleSpecifier instead of custom hack

* Fix offering auto imports to paths within node modules

* Rename things and make comments better

* Add another reexport test

* Inline `symbolHasBeenSeen`

* Simplify forEachAlias to findAlias

* Add note that symbols is mutated

* Symbol order doesn’t matter here

* Style nits

* Add test with nested package.jsons

* Fix and add tests for export * re-exports

* Don’t fail when alias isn’t found

* Make some easy optimizations

* Clean up memoization when done

* Remove unnecessary semicolon

* Make getSymbolsFromOtherSourceFileExports pure

* Cache auto imports

* Revert "Cache auto imports"

This reverts commit 8ea4829587.

* Handle merged symbols through cache

* Be safer with symbol declarations, add logging

* Improve cache invalidation for imports and exports

* Check symbol presence first

* Only run cache invalidation logic if there’s something to clear

* Consolidate cache invalidation logic

* Fix reuseProgramStructure test

* Add more logging

* Only clear cache if symbols are different

* Refactor ambient module handling

* Start caching package.json stuff

* Support package.json searching in fourslash

* Move import suggestions cache to Project

* Start making more module specifier work available without having the importing file

* Going to backtrack some from here

* Get rid of dumb cache, fix node core modules stuff

* Start determining changes to a file have invalidated its own auto imports

* Move package.json related utils to utilities

* Add failing test

* Make first test pass

* Don’t filter when there’s no package.json, fix scoped package imports

* Use type acquisition as a heuristic for whether a JS project is using node core

* Make same fix in getCompletionDetails

* Fix re-exporting

* Change JS node core module heuristic to same-file utilization

* Remove unused method

* Remove other unused method

* Remove unused triple-slash ref

* Update comment

* Refactor findAlias to forEachAlias to reduce iterations

* Really fix re-exporting

* Use getModuleSpecifier instead of custom hack

* Fix offering auto imports to paths within node modules

* Rename things and make comments better

* Add another reexport test

* Inline `symbolHasBeenSeen`

* Simplify forEachAlias to findAlias

* Add note that symbols is mutated

* Symbol order doesn’t matter here

* Style nits

* Add test with nested package.jsons

* Fix and add tests for export * re-exports

* Don’t fail when alias isn’t found

* Make some easy optimizations

* Clean up memoization when done

* Remove unnecessary semicolon

* Make getSymbolsFromOtherSourceFileExports pure

* Cache auto imports

* Revert "Cache auto imports"

This reverts commit 8ea4829587.

* Handle merged symbols through cache

* Be safer with symbol declarations, add logging

* Improve cache invalidation for imports and exports

* Check symbol presence first

* Only run cache invalidation logic if there’s something to clear

* Consolidate cache invalidation logic

* Fix reuseProgramStructure test

* Add more logging

* Only clear cache if symbols are different

* Refactor ambient module handling

* Finish(?) sourceFileHasChangedOwnImportSuggestions

* Make package.json info model better

* Fix misplaced paren

* Use file structure cache for package.json detection when possible

* Revert unnecessary changes in moduleSpecifiers

* Revert more unnecessary changes

* Don’t watch package.jsons inside node_modules, fix tests

* Work around declaration emit bug

* Sync submodules?

* Delete unused type

* Add server cache tests

* Fix server fourslash editing

* Fix packageJsonInfo tests

* Add node core modules cache test and fix more fourslash

* Clean up symlink caching

* Improve logging

* Function name doesn’t make any sense anymore

* Move symlinks cache to host

* Fix markFileAsDirty from ScriptInfo

* Mark new Project members internal

* Use Path instead of fileName

* Rename AutoImportSuggestionsCache

* Improve WatchType description

* Remove entries() from packageJsonCache

* Fix path/fileName bug

* Also cache symlinks on Program for benefit of d.ts emit

* Let language service use Program’s symlink cache
2019-09-27 13:38:31 -07:00
Nathan Shively-Sanders fefb857847 Use only immediately preceding JSDoc
Now only the immediately preceding jsdoc of a node is retrieved by
getJSDoc, although it still does the correct non-local lookup for nodes
like ParameterDeclaration.

This doesn't change parsing or binding, which use the per-node Node.jsdoc
property directly. But it does change everything that relies on getJSDoc,
which includes the checker and language service.

Fixes #32062, which contains the analysis that justifies the change.
2019-06-29 08:05:10 -07:00
Sheetal Nandi 73bf2684ac Rename to use contextSpan 2019-06-13 12:41:21 -07:00
Sheetal Nandi edad317395 Fourslash server tests 2019-06-06 10:41:33 -07:00
Sheetal Nandi 00cea41b65 Add sortText depending scope of symbols
Fixes #15024
2019-05-20 15:53:51 -07:00
Daniel Rosenwasser 9cd5f2dd3c Add regression test. (#29433) 2019-01-15 17:39:02 -08:00
Wesley Wigham cd08a22ef5
Clamp calculated sourcemap positions rather than throwing (#28583)
* Clamp calculated sourcemap positions rather than throwing, to allow the underlying file to drift out of date with the sourcemap without a crash

* Clamp line as well
2018-11-16 16:05:07 -08:00
Andy c22c7e687d
Strcter testing for global completions; and 'excludes' can only be a string (#28349) 2018-11-05 16:16:28 -08:00
Mine Starks 1fbabd5534 Merge pull request #28106 from minestarks/configure-plugins
configurePlugins command for tsserver
2018-10-29 14:06:40 -07:00
Andy c97fc64972
Always use verify.completions when testing completions (#28137) 2018-10-29 10:03:25 -07:00
Andy cc7bfc0349
Support testing jsdoc tags of completions (#26962) 2018-09-13 08:47:50 -07:00
Andy b1430e5e2c
Avoid adding duplicate completion from contextual keyword (#26947) 2018-09-07 12:18:03 -07:00
Andy 794f3a5e76
goToTypeDefinition: Go to function return type (#25952)
* goToTypeDefinition: Go to function return type

* Add more tests

* If a function returns 'void' or some other type with no definition, just return the function definition.
2018-08-07 12:54:19 -07:00
Wesley Wigham 23eb591e01
Lookup files by resolved Path and not by fileName in sourcemapDecoder when querying program (#25908)
* Check if the file returned by the program actually refers to the same file as we intend

* Simplify
2018-07-24 15:44:22 -07:00
Wesley Wigham 797d8bd07b
Call toPath on sourceRoot to ensure it is always absolute (#25838)
* Call toPath on sourceRoot to ensure it is always absolute

* Leave canonicalization to avoid a Path/string union
2018-07-24 14:14:41 -07:00
Andy 64555aa6a9
navigateTo: Collect results from all referenced projects. (#25283)
* navigateTo: Collect results from all referenced projects.

* Don't use project references, just source maps

* Move more code to session

* Test when implementation file is deleted

* Use tsserver tests instead of fourslash tests to ensure session is used

* Support find-all-references

* Restore fourslash tests

* Update emit baselines (added missing newline)

* Support rename

* @weswigham code review

* Don't open/close files

* Avoid growing `toDo` too eagerly

* @sheetalkamat code review

* Also get symlinked projects for originalLocation

* Update API (#24966)

* More @sheetalkamat code review

* Remove unnecessary test

* Update API (#24966)
2018-07-05 15:39:03 -07:00
Andy efc1b7df08
More thoroughly test navigateTo (#25239)
* More thoroughly test navigateTo

* Fix #25233 and #25237

* Update API (#24966)
2018-07-02 19:25:27 -07:00
Benjamin Lichtman f0e5056063 Add test 2018-06-29 11:34:58 -07:00
Andy 9d42ab983d
implementations: Use declaration name for the span (#24537)
* implementations: Use declaration name for the span

* Always get name in nodeEntry
2018-05-31 13:32:02 -07:00
Andy 77371679be
Support getting references even if quickInfo failed (#24476)
* Support getting references even if quickInfo failed

* Add test
2018-05-30 14:11:36 -07:00
Nathan Shively-Sanders aa7e2b0f07
Add callback tag, with type parameters (#23947)
* Add initial tests

* Add types

* Half of parsing (builds but does not pass tests)

* Parsing done; types are uglier; doesn't crash but doesn't pass

* Bind callback tag

Builds but tests still don't pass

* Only bind param tags inside callback tags

* Fix binding switch to only handle param tags once

* Checking is 1/3 done or so.

Now I'm going to go rename some members to be more uniform. I hate
unnnecessary conditionals.

* Rename typeExpression to type (for some jsdoc)

(maybe I'll rename more later)

* Rename the rest of typeExpressions

Turns out there is a constraint in services such that they all need to
be named the same.

* Few more checker changes

* Revert "Rename the rest of typeExpressions"

This reverts commit f41a96b24d.

* Revert "Rename typeExpression to type (for some jsdoc)"

This reverts commit 7d2233a00e.

* Finish undoing typeExpression rename

* Rename and improve getTypeParametersForAliasSymbol

Plus some other small fixes

* Core checking works, but is flabbergastingly messy

I'm serious.

* Callback return types work now

* Fix crash in services

* Make github diff smaller

* Try to make github diff even smaller

* Fix rename for callback tag

* Fix nav bar for callback tag

Also clean up some now-redundant code there to find the name of typedefs.

* Handle ooorder callback tags

Also get rid of redundant typedef name code *in the binder*. It's
everywhere!

* Add ooorder callback tag test

* Parse comments for typedef/callback+display param comments

* Always export callbacks

This requires almost no new code since it is basically the same as
typedefs

* Update baselines

* Fix support for nested namespaced callbacks

And add test

* Callbacks support type parameters

1. Haven't run it with all tests
2. Haven't tested typedef tags yet
3. Still allows shared symbols when on function or class declarations.

* Template tags are now bound correctly

* Test oorder template tags

It works.

* Parser cleanup

* Cleanup types and utilities

As much as possible, and not as much as I would like.

* Handle callback more often in services

* Cleanup of binder and checker

* More checker cleanup

* Remove TODOs and one more cleanup

* Support parameter-less callback tags

* Remove extra bind call on template type parameters

* Bind template tag containers

Doesn't quite work with typedefs, but that's because it's now stricter,
without the typedef fixes. I'm going to merge with jsdoc/callback and
see how it goes.

* Fix fourslash failures

* Stop pre-binding js type aliases

Next up, stop pre-binding js type parameters

* Further cleanup of delayed js type alias binding

* Stop prebinding template tags too

This gets rid of prebinding entirely

* Remove TODO

* Fix lint

* Finish merge with use-jsdoc-aliases

* Update callback tag baselines

* Rename getTypeParametersForAliasSymbol

The real fix is *probably* to rename Type.aliasTypeArguments to
aliasTypeParameters, but I want to make sure and then put it in a
separate PR.
2018-05-17 09:28:11 -07:00
Andy e1f22ac568
Combine signatureHelp testing methods (#24132) 2018-05-15 12:34:53 -07:00
Andy 7fa5f70b9a
Remove verify.referencesAre, verify.referencesOf, verify.rangesReferenceEachOther (#23900) 2018-05-07 10:08:38 -07:00
Mohamed Hegazy e52efb04f3 Fix #22419: Add kind field to OutliningSpan 2018-05-03 16:28:55 -07:00
Andy d1fde3786c
Symbol kind for a method on a mapped type should still be 'method' (#23478) 2018-04-17 14:07:59 -07:00
Andy f2f2393f4b
convertFunctionToEs6Class: Copy comments from constructor to class (#22738) 2018-03-22 08:12:02 -07:00
Mohamed Hegazy c335c3803c
Fix #22133: Expose getOutliningSpans on the server protocol (#22400)
* Fix #22133: Expose getOutliningSpans on the server protocol

* Remove debugger statement from test
2018-03-09 08:50:47 -08:00
Andy 87c3cca3f0
Make convertFunctionToEs6Class a codefix (#22241)
* Make convertFunctionToEs6Class a codefix

* Change diagnostic message
2018-03-02 12:57:29 -08:00
Andy 6385c66215
Simplify diagnostics fourslash tests (#22245) 2018-03-01 07:34:51 -08:00
Andy 0b1e21794d
fourslash diagnostics tests: use objects instead of strings (#22193) 2018-02-26 14:55:26 -08:00
Andy 16f3b93ffd
Simplify TextSpan creation (#21306)
* Simplify TextSpan creation

* Rename 'start' to 'pos' where possible
2018-02-08 13:51:10 -08:00
Andrew Casey 3ca1cc406a Clean up TODOs for #18445 2018-01-17 15:29:41 -08:00
Priyantha Lankapura 743d8dbe0a Fix to remove extra space between function and array index. (#21113)
https://github.com/Microsoft/TypeScript/issues/21111
2018-01-10 09:30:35 -08:00
Andy 2efc92d1dc
Adjust formatting rule priority: Never delete space after case (#20615) 2017-12-18 10:54:54 -08:00
Armando Aguirre 16c3255988 Updated an incredible amount of tests. 2017-10-18 15:49:46 -07:00
Sheetal Nandi 03441fe120 Merge branch 'master' into projectRootAsCurrentDirectoryInEmit 2017-10-04 18:48:16 -07:00