Commit graph

6104 commits

Author SHA1 Message Date
Wesley Wigham f7a97b7759
Cache accessibe symbol chains and serialized type parameter name generation (#43973)
* Cache accessibe symbol chains, type parameter name generation

* Move signature declaration helper length approximation to start of function

* Add node result caching internal to `typeToTypeNodeHelper`

* Suggestion from PR
2021-05-12 12:11:20 -07:00
Wenlu Wang 5b1e873b03
Update diagnostic message and quickfix for parameter property (#44010) 2021-05-08 23:22:20 -07:00
Orta Therox 6bb481c9d3
Support semantic highlights for JS files (#43992)
* Switches from never allowing semantic highlight on JS to only doing it if we have a valid source file

* Adds a way to test and validate that an arbitrary JS file gets semantic classification results

* Revert to just dropping the if statement
2021-05-07 20:02:26 +01:00
Nathan Shively-Sanders f6303652d2
Improve errors for incorrectly nested export default (#43967)
* Improve errors for incorrectly nested export default

The compiler and services don't handle incorrectly nested
`export default` well right now:

```ts
export = (x,y) => {
  export default { }
}
```

Asking for document highlights, find all references or quick info on
'export' or 'default' cause a crash. After the crash is fixed, the error
message is confusing and wrong: "An export assignment cannot be used outside a module."

This PR:

1. Skips document highlights for incorrectly nested export default.
2. Skips find all refs for incorrectly nested export default.
3. Switches the fallback binding for incorrectly nested export default
from Alias to Property. Neither is correct, but Property doesn't cause a
crash in alias resolution.
4. Improves the error message to reflect a post-ES module world, which
has export default and 'module' means 'ES module', not 'namespace'.

Fixes #40082 and the related bugs mentioned above.

* address PR comments
2021-05-07 08:09:38 -07:00
Oleksandr T e0d7703cf3
fix(43939): forbid converting getters to async/await (#43944) 2021-05-06 01:48:54 -07:00
Oleksandr T 6f8c3b0c99
fix(43957): insert Override keyword after static modifier (#43959) 2021-05-05 08:52:50 -07:00
Nathan Shively-Sanders 7a8c5a0001
Displayparts resolves non-values in link tags (#43903)
Previously, the name resolution for link tags in displaypart generation
mistakenly required a valueDeclaration. Now it uses the first
declaration if there is no valueDeclaration, so that types and
namespaces will also resolve.

This is another instance of using valueDeclaration as "the default
declaration", which doesn't apply to types.

Fixes #43868
2021-04-30 14:17:54 -07:00
Sheetal Nandi c96b472e0b
Handle localness in special cases by checking exported variable assignment (#43851)
* Handle localness in special cases by checking exported variable assignment
Fixes #42976

* Fix existing tests where arrow now behaves similar to function expression

* Update src/services/goToDefinition.ts
2021-04-30 13:17:59 -07:00
Xu Zhuo 4ecb563aa4
Complete constructor keyword after property declaration (#43654)
* Complete `constructor` keyword after property declaration.

* Fix logical errors.

* Fix for more universal situations.

* Only provide completions if property declaration is terminated.

* Simplify many logical conditions.

* Make the fix more reliable.

* Narrowing the fix.
2021-04-29 11:16:51 -07:00
Andrew Branch 3de706a852
Don’t create invalid type-only imports during add missing import (#43828) 2021-04-26 11:52:34 -07:00
Andrew Branch b9c1e98544
Fix completions of exports elsewhere in same file (#43755)
* Fix completions of exports elsewhere in same file

* Undo messing up JSDoc-annotated module.exports assignments

* Add other failing contextual type test

* Rearrange contextual type logic for special assignments

* Rename helper function
2021-04-26 09:13:09 -07:00
Oleksandr T 482f781386
fix(43559): allow renaming in files with no-default-lib enabled (#43579) 2021-04-23 16:56:33 -07:00
Nathan Shively-Sanders d171eee044
Omit spaces after https in jsdoc comments (#43800)
* Omit spaces after https in jsdoc comments

for tags with names.

Fxes #42581

* fix semicolon lint
2021-04-23 16:23:34 -07:00
Zak Miller c552a4bf82
fix(42829) ignore preceeding jsx whitespace (#43452) 2021-04-22 15:12:05 -07:00
Tiago Tristao 3d24b85f9e
Completion list for type literals in type arguments (#43526)
* Completion list for type literals in type arguments

* Add tests

* Refactor for better readability

* - Support non-identifier keys
- Move main logic onto tryGetGlobalSymbols function
2021-04-20 10:24:17 -07:00
Sang f2705294ac
Fix object literals lack of this references (#43572)
* fix: object literals lack of this references

* test: improve cases
2021-04-20 10:06:08 -07:00
Jean Pierre 8513f78058
Fix getCodeFixesAtPosition for ts(2339) thows error False expression: Token end is child end (#43645)
* Fix getCodeFixesAtPosition for ts(2339) thows error False expression: Token end is child end
Fixes #43191

* Add test
2021-04-20 10:00:34 -07:00
Josh Goldberg a910c8df13
Added skipDestructiveCodeActions argument to organize imports server command (#43184)
* Stopped removing unused imports in files with syntactic errors

* Added allowDestructiveCodeActions arg

* Updated .d.ts baselines

* Stop factoring syntax errors. Weird that no tests break...

* Have args extend scope so it is not a breaking change

* Update src/harness/harnessLanguageService.ts

Co-authored-by: Jesse Trinity <jetrinit@microsoft.com>

* Fixed API breaking change, and renamed to skip

* Always with the baselines

* One more .d.ts baseline to fix

* Remove blank line in src/harness/harnessLanguageService.ts

Co-authored-by: Jesse Trinity <jetrinit@microsoft.com>
2021-04-20 09:04:17 -07:00
Armando Aguirre 1a04b17adc
Fix organize imports overlap (#43228)
* Fix organize imports overlap

* Refactored multiline end position

* Added tests for single line trailing trivia

* Fix rearranging imports

* Fix lint error

* PR coments
2021-04-19 15:10:57 -07:00
Andrew Branch f74f9cac13
Add telemetry properties for import statement completions (#43664) 2021-04-13 16:17:52 -07:00
Armando Aguirre 5a6a499d0e
Fix sending correct symbol when using commonjs require and destructuring (#43511)
* Fix sending correct symbol when using commonjs require and destructuring

* Check BindingElement
2021-04-13 15:06:34 -07:00
Andrew Branch 06a73655d0
Don’t error for missing await when promise is referenced in condition body (#43593) 2021-04-13 12:15:48 -07:00
Kunal Desai 0487b38d06
Catch hover on as const (#43588)
* Catch hover on as const

* Update test based on feedback
2021-04-12 11:43:47 +01:00
Sang a354a77030
Improve rendering of JSDoc comment text with displayparts (#43390)
* feat(services): jsdoc use custom name for display parts

* fix(services): jsdoc typo

* feat(services): revert jsDoc changes

* feat(services): jsdoc improve displayparts with more comment kinds

Improve rendering of JSDoc comment text with displayparts for:

- `@typedef`
- `@callback`
- `@param`
- `@property`

* feat(services): jsdoc improve displayparts for template

* test: accept baseline

* test: update jsdoc parameterName

* feat: resolve pr comments

* test: add fourslash tests for jsdoc callback, typedef

* test: accept baselines

* test: revert changes for api baselines

* refactor: naming

* refactor: code quality

* refactor: clean up code as to pr comments
2021-04-09 09:44:44 -07:00
Armando Aguirre 2f82d02361
Fix Add all missing imports when ordered alphabetically (#43453)
* Refactored insertNodeInlistAfter to use next elements position

* Consider trivia on insertNodeInListAfter
2021-04-07 16:02:26 -07:00
Oleksandr T eebb89533b
fix(43495): insert Override keyword after accessibility modifier (#43504) 2021-04-06 12:03:41 -07:00
Michael サイトー 中村 Bashurov 3b06ef1a73
Add asserts to type only symbols meaning exclusion (#43382)
Fixes #42180
2021-04-05 15:29:51 -07:00
Andrew Branch ffe925ddd5
Go to definition: pass unverified through server (#43483)
* Pass `unverified` through server

* Update protocol baseline

* Fix unit tests

* Fix other tests
2021-04-05 13:42:25 -07:00
Sheetal Nandi 4b556e37db
Handle document Registry to distinguish between files with same name and document registry key(compiler options affecting source file) but different ScriptKind (#43474)
* Test that fails because of change in scriptKind of untitled file

* buckets are keyed with DocumentRegistryBucketKey

* Use scriptKind in document Registry to distinguish between files
Fixes #42613
2021-04-05 13:27:34 -07:00
Zuckjet f621d67467
fix(42605): support refactoring for export default assignment without equal (#42936) 2021-04-05 11:59:45 -07:00
Oleksandr T 5268264e64
fix(43316): omit to suggest converting to async function if a void is explicitly returned (#43358) 2021-04-05 11:09:33 -07:00
Sang f9b35cd302
Add @link jsdoc auto-complete (#43475)
* feat(services): jsdoc add link tag name

* test: add jsdoc inline test
2021-04-01 17:02:50 -07:00
Oleksandr T 819651eb5f
fix(43313): add parentheses to a type assertions (#43315) 2021-03-30 15:29:02 -07:00
Sang a8ee22f73d
"fix(services): convert to es6 module generate invalid code with .default" (#43309) 2021-03-30 15:24:31 -07:00
Daniel Rosenwasser a3d207a905
Improve (and actually use) "always truthy promise" error (#43023)
* Modify error message and actually use the error message.

* Accepted baselines.
2021-03-29 12:44:05 -07:00
Wenlu Wang 2f0c8b2bea
--noImplicitOverride (#39669)
* wip: add types

* wip

* Add cases

* Add some case

* Add more check

* accept baseline

* add abstract abd declare method

* add override in declaration

* accept baseline

* add property override

* Fix decalre modifier

* update baseline

* Add more cases

* make lint happy

* make lint happy

* Update description

* Add codefix

* simplify code

* accept baseline

* Update desc

* Accept baseline

* Add override completions

* filter out implements field in override context

* fix tests

* Add parameter property check

* Accept baseline

* acept baseline

* Add parameter property to declaration code action

* Add quickfix for override parameter property

* fix code style

* Add override with interface tests

* Add more cases about modifier position

* rename flag

* rename flags

* Added tests.

* Accepted baselines.

* Always issue errors for unnecessary 'override' modifiers.

* Accepted baselines.

* Override perf (#4)

* try cache check result

* pre check for override

* Do not issue error if implement abstract

* Add abstract-spec check

* Avoid override dead lock

* Add more case

* Add codefix for new error

* Fix error message

* Add jsdoc override tag (#6)

* Override jsdoc tag (#7)

* accept baseline

* Disallow codefix in js

* update baseline

* Omit override in d.ts

* Add more case in js

* Accept baseline

* fix override js test

* fix crlf

* Revert merge conflict changes

* Accept baseline

* Avoid space

* Fix CR issues

* Accept baseline

* Fix typo and add more check

* Fix error name

Co-authored-by: Daniel Rosenwasser <Daniel.Rosenwasser@microsoft.com>
2021-03-26 16:29:22 -07:00
Andrew Branch 2d6a490363
Import statement completions (#43149)
* WIP

* WIP

* Get completion details working

* Start unifying eager and lazy auto imports

* Fix export=

* Fix completion details for totally misspelled names

* Almost fixed duplication...

* Fix remaining completion tests

* Refactor to support multiple origins for same symbol

* Make import fixes make slightly more sense

* Add cache back in

* Set insertText based on import kind

* Update API baselines

* Add semicolons, snippet support, and sourceDisplay

* Add some tests

* Update baselines

* Fix pattern ambient modules appearing in auto imports

* Fix tests

* Remove commented code

* Switch to valueDeclaration for getting module source file

* Small optimizations

* Cache module specifiers / importableness and export map separately

* Fix and test cache invalidation logic

* Update API baselines

* Add separate user preference for snippet-formatted completions

* Require first character to match when resolving module specifiers

* Fix AutoImportProvider export map cache invalidation

* Really fix auto import provider export map invalidation

* Update test added in master

* Use logical or assignment

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Simply conditional by reversing

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* When file is deleted need to marked correctly in the project as removed file

* Simplify hasAddedOrRemovedSymlinks with cherry-picked fix

* Ensure replacement range is on one line

* Update baselines

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 14:47:07 -07:00
Sheetal Nandi a545ab1ac2
Cache resolved project references and watch wild card directories from them to update them (#42929)
* Test for not watchiong referenced projects fileNames and invalidating it

* Add watching wild card directories and caching parsed command line for projects so that its shared

* Handle config file watching and commandline cache together

* Watch extended files for commndline cache instead of project

* Use extended config cache now that we are watching extended config files

* Structure for getParsedCommandLine from the LS

* Adding some more skeleton with todos

* getParsedCommandLine on WatchCompilerHost

* Tests for Watch, LS scenarios

* Handle getParsedCommandLine so we are looking at all things for referenced

* Cleanup and commenting

* Test for transitive references with tsc-watch

* Cache parsed command line even if host implements getParsedCommandLine

* Cleanup

* Cleanup

* Some tests to verify exclude from referenced project doesnt trigger the update

* Baseline when program is same

* Test for incremental scenario

* Tests for output from referenced project

* Comments
2021-03-26 13:23:03 -07:00
Ron Buckton fbd7f7db20
Update typescript-eslint to latest (#43381) 2021-03-25 14:46:16 -07:00
Eli Barzilay eb804a9706 getSemanticDocumentHighlights: don't fail...
...when missing `program.redirectTargetsMap` info.  This assertion fails
in the added test case -- looks like there is no entry in
`program.redirectTargetsMap` when it comes from a file that is no in the
project.  So in this case don't follow the (missing) info, and instead
drop the highlight.

Fixes #33722.
2021-03-25 15:48:34 -04:00
Titian Cernicova-Dragomir e638af7560
ES private class elements (#42458)
* Added support for private identifier methods.

* Added tests for private methods.

* Added check to only not allow private name method signatures in anything except classes.
Changes objects literal checking to not bail on first private name found in object literal.

* Added private accessors tests

* Transform private methods

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Rename shouldTransformPrivateFields

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Use a single WeakSet for brand-check

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add a test for using private methods in static field initializers

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add breaking checker test

Private methods inside class expressions should not error.

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add to instances once per-instance

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: evaluate receiver and rhs expressions before throwing on readonly assignment

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Add a test for evaluating rhs before readonly assignment

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Transpile private accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: handle readonly/writeonly accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* accept baseline

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for private setter without a getter

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: getAllUnscopedEmitHelpers

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: better handling of duplicate names

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Fixed wrong error message for private methods in class expressions.

* change error message

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for async private methods with a higher target

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: setter assignment returns rhs value

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for setter assignment return value

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: handle duplicate accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add tests for duplicate accessors

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* docs: add missing parameter docs

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Fixed failing test.

* baseline-accept: ordering changes

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* fix: attach weakSetName to property declaration

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test for nested private methods

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* add a test with any

Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com>

* Added support for static private fields accessors and methods.

* Added error message for private identifiers used with static decorators. There is no spec to go with this behavior as of yet.

* Fixed emit static bug that used private names outside of classes for initialization in esnext. Fixed issue where nested privates produce incorrect brand check.

* Added tests for private static fields methods and accessors.

* Fixed error messages and tests after merge.

* Accept new baseline.

* Improved duplicate identifier checks for static private class elements.

* Added error when using initializers with private static fields when useDefineForClassFields is not specified and target is esnext.

* Fixed code review issues.

* Removed semantically wrong emit on `useDefineForClassFields:true` with `target:esnext`

* Changed emit for uninitialized private static fields.

* Added runtime error in helper if a static private field is accessed before it was declared.

* Fixed code review comments for private identifier static class elements.

* add debug.assertNever for unknown node type (#53)

* Fixed code review issues.

* Fixed code review issues for private class elements.

* Fixes class shadowing when checking access to a private static class element.

* fix private methods/accessors in class expr inside a loop

* collapse switch case

* fix class name

* simplify getPrivateMethodsAndAccessors

* remove findPreviousAccessorInfo

* lazily create weakSetName identifier

* do not allocate a node if not needed in visitMehodDeclaration (#55)

* Removed all the emit helpers for private identifier methods accessors and modified the existing helpers for get and set fields to do the same job.

* Simplified emit for private identifier class elements.

* do not clone the receiver (#57)

* leave bad code in for #constructor and duplicate private names (#58)

* Added check for WeakSet collision.

* Added error for using a set only accessor.

* update keyof tests and ?? (#62)

* replace ?? with ||

* update keyof tests

* fix emit helpers comments

* produce an error if private field helpers are not up to date

* add tests

* fix setter-only compound assignment

* fix tests

* fix duplicated trailing comments (#64)

* clear receiver pos and setTextRange on helper calls

Co-authored-by: Kubilay Kahveci <kahvecikubilay@gmail.com>
2021-03-24 18:15:50 -07:00
Eli Barzilay 6ce82ab02e deleteDeclaration: don't crash on the top node.
A misbehaved client can sometimes cause the server to reach
`deleteDeclaration` with the SourceFile, and it will crash due to no
`node.parent`.  I couldn't find a good way to create a test for it, but
I could trigger it manually by having a file with just a `,`, and
sending an explicit `getCodeFixes` command to the server with
`errorCodes: [6133]`.

Do three things to improve this:

1. `textChanges.ts`: if we get here with the root node, delete it
   instead of failing.

2. `fixUnusedIdentifier.ts`: check that we don't `delete` a node that is
   the whole source file, so the error is more focused (should have more
   similar failure stacks).

3. `session.ts`: when there was any failure in `getCodeFixes`, check if
   the input had a diag code that does not appear in the requested text
   range, and throw an error saying that the failure is probably a
   result of a bad request.

Closes #33726 (probably not fixing it, but making it easier to find the
cause)
2021-03-24 19:25:06 -04:00
Nathan Shively-Sanders dcc27ebaf2
@link support, second try (#43312)
* Revert "Revert "Editor support for link tag (#41877)" (#43302)"

This reverts commit 451d4354b9.

* Fix parsing @link at end of comment

* Parse comments as string when no @link occurs

* fix lint
2021-03-22 16:39:35 -07:00
Simar Bassi 462271854d
Fix Issue #39155 (importModuleSpecifierEnding does not apply for module specifier completions) (#42467)
* Pass preferences down to getCompletionEntriesForRelativeModules

* Add preferences to getExtensionsOptions call

* Add test case

* Fix test case typos
2021-03-22 14:10:41 -07:00
Hossein 6a83ae19e2
[GH-43213] Fix duplicate comments printed in quick info section (#43240)
* Concat on unique values

* more changes

* only push values to array if unique

* address review comments

* Fix lint

* removw foeachunique
2021-03-19 14:14:32 -07:00
Nathan Shively-Sanders 451d4354b9
Revert "Editor support for link tag (#41877)" (#43302)
This reverts commit ec77bff332.
2021-03-18 14:42:25 -07:00
Nathan Shively-Sanders ec77bff332
Editor support for link tag (#41877)
* Initial scribbles

* Compiles but provides spans instead of location pairs

Probably need to fork the services/server types and provide a conversion
with Session.toFileSpan. Not sure where to put the conversion.

* Switch to DocumentSpan

In theory this is already better supported, but not sure practise bears
that out.

* Builds w/protocol types + conversions

* cleanup:better names and scrub TODOs

* fix test harness too

* Misc

1. Simplify protocol after talking to @mjbvz.
2. Add more tests.
3. Initial notes about where to add parsing.

* Parse and store links in the compiler

The text of the link is still stored in the comment text, but that's now
kept in an object instead of just a string. Each link has the parse for
the entity reference, if there is one.

Needs lots more tests -- this just makes all the existing jsdoc tests
pass.

* more tests and some fixes

* Fix other failing tests

* fix bad merge

* polish parser

* improve names and array types

* slight tweaks

* remove some done TODOs

* more tests + resulting fixes

* add+fix cross-module tests

* Support `@see {@link`

Plus find-all-refs support equivalent to @see's.

* add server test

* Make comments actually part of the AST

* Add span for link.name in language service/protocol

* Make checker optional in getJSDocTags

Also change to JSDocCommentText from JSDocCommentComment

* Use getTokenValue instead of getTokenText

Measure twice, slice once

* Add missing support for top-level links

The language service and protocol were missing support for top-level
links. This commit adds that plumbing.

* add string back to comment type in node constructors

* Full parse of link tags and jsdoc comment text

- Doesn't pass fourslash yet, I'm going to switch to baselines for
  failures there.
- Still needs some work on the protocol to convert file+offset to
  file+line+offset.

* fix lint

* Fix missing newlines in inferFromUsage codefix

* Parse jsdoc comments as text node/link array

And switch to line+character offsets in the protocol

* Fix fourslash tests

Mostly ones that can't be baselined, but I switched a couple more over
to baselines

* Improve types and documentation

* Test+fix @link emit, scrub other TODOs

* update API baselines

* test that goto-def works with @link

* Split link displaypart into 3

One for link prefix and suffix, one for link name, and one for link
text.

* update baselines

* Provide JSDocTagInfo.text: string to full clients by default

Instead of upgrading them to displayparts.

* Real server tests

* Disambiguate {@link} and @param x {type}

They are ambiguous; previously the parser preferred the type
interpretation, but will now look ahead and parse links instead when the
prefix is `{@link`.

* Add explanatory comment in test

* fix location in richResponse in protocol

* update API baseline

* Address PR comments

1. Add a cross-file goto-def test.
2. Switch from per-message args to UserPreference.

* use arraysEqual from core
2021-03-16 16:26:01 -07:00
Oleksandr T 3da5982c9a
fix(43254): show named tuple member type (#43273) 2021-03-16 12:56:12 -07:00
Armando Aguirre 36f7623225
Fix jsx formatting (#42671)
* Refactored scanJsxToken when is formatting

* Added bug regression test

* Simplify JsxText formatting

* Renamed isFormatting to allowMultilineJsxText

* Updated baselines
2021-03-13 01:00:42 -08:00
Ryan Cavanaugh 79d3058b83
Don't crash when renaming a JS property declared via module.exports (#40297)
Fixes #38070

When the originating definition was of the form
```js
module.exports.foo = expr
```
we were incorrectly trying to call `resolveName` on just the `foo` portion to get the "local" symbol, which simply failed to resolve (or would have resolved to the wrong thing), but for this form, the local symbol is just the containing property access expression
2021-03-11 07:23:19 -08:00
Wenlu Wang b20331a4db
Fix missing func modifier (#40379)
* Fix missing function modifier

* Update src/services/refactors/convertArrowFunctionOrFunctionExpression.ts

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-03-10 09:34:31 -08:00
Nathan Shively-Sanders 3d53661605
Don't inherit jsdoc tags from overloaded signatures (#43165)
Previously, when getting jsdoc for signatures, the services layer would
get the jsdoc tags for the base symbol of a signature if it was
present. This is fine except when the base was overloaded. In that case,
the multiple signatures of the overload would all contribute jsdoc,
which is not correct.

A more correct fix would be to resolve overloads to the base, but
the compiler doesn't have this capability and adding it or jury-rigging
it seems like it would be complex, inappropriate for a fix to ship in a
patch version.

Co-authored-by: Orta Therox <git@orta.io>

Co-authored-by: Orta Therox <git@orta.io>
2021-03-09 12:28:36 -08:00
Oleksandr T f1c911b6c6
fix(43006): skip trivia in a function name (#43021) 2021-03-02 16:32:28 -08:00
Nathan Shively-Sanders c497b487a7
Add undefined to Symbol.valueDeclaration (#43033)
* About halfway through the checker

I'm going to merge with master to avoid clashing with the declaration
fix.

* Add undefined to Symbol.valueDeclaration

Also add undefined to a number of utility functions that have always
accepted it, but never added it to their type.

* Fix lint from code review

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* remove obsoleted fix from inferFromUsage

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-03-02 12:36:26 -08:00
Andrew Branch 4b67b4a7bc
Support go-to-definition for imports of arbitrary files (#42539)
* Support go-to-definition for imports of scripts and arbitrary files

* Support go-to-definition for non-existent files

* Add missing file property

* Use `isExternalModuleNameRelative` instead of `!pathIsBareSpecifier`

* Add partial semantic test

* Combine with symbol search for non-source-file file references

* Fix and accept API baselines

* Fix useless or

* A definition is unverified if the file path was a guess, even if a source file has that path
2021-03-01 15:15:09 -08:00
Nathan Shively-Sanders aa67b16e99
Add undefined to Symbol.declarations' type (#42975)
* Add undefined to Symbol.declarations' type

Symbol.declarations now has type `Declaration[] | undefined`.

I made a mistake somewhere in the checker related to JS checking, so
there are quite a few test failures right now.

* undo clever change to getDeclaringConstructor

* Address PR comments

1. More early-returns.
2. More line breaks.
2021-03-01 14:32:28 -08:00
Andrew Branch 993c503c84
Add 'data' property to completion entry for better coordination between completions and completion details (#42890)
* Add 'data' property to completion entry for better cooperation between completions and completion details

* Add doc comment

* Update API baselines

* Add server test

* Test session’s Full result

* Fix tests

* stableSort to fix server fourslash test

* Explicit verification of data parameter
2021-03-01 12:09:45 -08:00
Ron Buckton 68b0323b72
Refactor emit substitution into transform (#42676)
* Refactor emit substitution into transform

* Add reusable state machine for binary expressions

* Allow emitBinary to use state machine for comments/sourcemaps

* Switch core trampoline state back to arrays

* Switch binder to parallel stacks, temporarily partially revert emitBinary

* Add link to benchmark when posting perf results

* Ensure work stacks are per-execution

* Reenable comments and sourcemaps
2021-02-25 23:01:41 -08:00
Armando Aguirre 0791bb0f84
Merge pull request #42332 from a-tarasyuk/fix/42259
fix(42259): Outline and breadcrumb show wrong namespace name
2021-02-24 17:35:36 -08:00
Oleksandr T 896a2b49ac
fix(42923): add go-to-definition on unresolved shorthand properties (#42924) 2021-02-24 10:53:27 -08:00
Oleksandr T 9de8dbbfb8
fix(42833): add return type to methods with overloads (#42881) 2021-02-23 14:24:47 +00:00
Wesley Wigham 87d10eb055
Eliminate well known symbols as a concept in the checker and rely on unique symbols (#42543)
* Eliminate well-known symbols in the checker: 2021 edition

* Actually update the lib text to say unique symbol, too (this is unneeded with compat code in place, but this makes goto-def make more sense)

* Add test showing mismatched symbol constructor type interop

* Add more test cases for some other related issues this fixes

* Revert computed name change

* Style comments
2021-02-22 14:43:28 -08:00
Nathan Shively-Sanders 0ce5c4a7ee
improve isRequireVariableDeclaration parameters (#42865)
One parameter is always called with `true`, so drop it.
2021-02-19 09:34:05 -08:00
Andrew Branch 1fd71478f9
Fix duplicate auto-import completions (#42850)
* Fix duplicate auto-import completions

* Update src/services/completions.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-02-18 10:06:37 -08:00
Oleksandr T 7fca9267e6
fix(41740): disallow renaming/exclude from references default keyword (#41947) 2021-02-17 17:07:31 -08:00
Amin Pakseresht 20ce292484
Provide completion for partial expression on closing jsx tags (#42029)
* Provide completion for partial expression on closing jsx tags

* Add more cases and cover opening tag is parent parent of location

* Fix code style indentation

* Add some more notes

* Guarding null pointer

* Guarding null pointer 2

* PR reviews & adjustments 1

* Fix typos

* Better namings

* Remove failing test-case

* PR reviews & adjustments 2 - new approach

* More comments

* More comments 2

* PR reviews & adjustments 3

* Revert previous test-case file changes

* Write explicit completions from ranges

* PR reviews & adjustments 4 - adding exact entry

* Add another missing test-case

* Find jsx closing element by findAncestor

* Walk up till find jsx closing element

* Add one more test-case

* PR reviews & adjustments 4 - Pattern matching to get jsx closing element

* Minor change

* Linting fixes
2021-02-17 17:06:13 -08:00
Jesse Trinity d640313ff2
Expand extractSymbol ranges (#42770)
* allow partial selections of node ranges

* separate tests for better failure investigation

* gate span expansion behind invoked command

* add invoked test

* comment wording

* for test
2021-02-17 12:55:12 -08:00
Wenlu Wang d6a32e31ae
Fix import fix on react or react dev (#41950) 2021-02-16 10:28:48 -08:00
Oleksandr T e5294b4d3c
fix(42519): fix infer function return type quick fix with arrow functions without parens (#42532) 2021-02-12 14:38:29 -08:00
Oleksandr T ff5ae3561f
feat(42735): add single line comments to selection ranges (#42763) 2021-02-11 17:14:55 -08:00
Oleksandr T b7922147d3
fix(42714): do not show inferFunctionReturnType QF on function body (#42737) 2021-02-11 10:46:48 -08:00
Jesse Trinity 1b19af0f14
Refactor params for interface (#42652)
* apply refactor to interface methods

* handle calls

* no available refactors for union type

* add tests

* Update src/services/refactors/convertParamsToDestructuredObject.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* address comments

* Update src/services/refactors/convertParamsToDestructuredObject.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Update src/services/refactors/convertParamsToDestructuredObject.ts

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-02-09 13:30:31 -08:00
Eli Barzilay f462576ac2 Re-do tracing initialization and tests around calls
Make `tracing` either `undefined` or the same namespace as before.
Switching all calls to `tracing?.___` means that there is no cost for
a call or the arguments when tracing is not used.  Comparing two runs
without tracing (27 runs, drop 5+5, avg rest) I get:

    master:
      42.59s user 1.00s system 165% cpu 26.372 total
    changed:
      42.01s user 0.982 system 165% cpu 26.039 total

(Makes it all private, so no api changes.)
2021-02-08 15:41:35 -05:00
Oleksandr T 60a6240210
feat(42637): add generateReturn option to UserPreferences (#42642) 2021-02-05 15:24:48 -08:00
Andrew Branch 79ed041b6a
Fix Format Selection on JSDoc comments (#42411) 2021-02-05 10:37:47 -08:00
Nathan Shively-Sanders f1583f08a0
Signature help turns off current-parameter display for non-trailing rest parameters (#42592)
* Signature help: support non-trailing rest parameters

In signature help, the first rest parameter will always be the *last*
'current' parameter (disregarding types). Previously, the signature help
current-parameter highlight was only correct for trailing rest
parameters. However, with tuple types, you can now create non-trailing
rest parameters. This PR now correctly highlights non-trailing rest
parameters as the last 'current' parameter.

For example, `names` should be the current parameter in all the calls
below:

```ts
declare function loading(...args: [...names: string[], allCaps: boolean, extra: boolean]): void;

leading(/**/
leading('one', /**/
leading('one', 'two', /**/
```

And, because signature help doesn't do real overload resolution, `names`
is also the current parameter for other calls:

```ts
leading(1, 2, 3, 'ill-typed', /**/
leading('fine', true, /**/
```

* Change 'variadic' to 'rest'

* fix missed rename

* use single, original tuple instead

* Revert "use single, original tuple instead"

This reverts commit f0896f32ea.

* Improve sig help of trailing rest too

1. Trailing rest keeps highlight at end instead of going off the end.
2. Non-trailing rest disable highlight entirely (by putting the index
one past the end).

* update API baselines
2021-02-05 09:37:28 -08:00
Wesley Wigham 19db9ad675
Swapping the quote style of a string for completions should swap _all_ quotes in the string (#42650) 2021-02-04 13:56:34 -08:00
Andrew Branch 258be217a6
Fix completions crash on transient exported property named 'default' (#42583)
* Fix completions crash on transient exported property named default

* Revert simplification, both conditions were needed
2021-02-04 10:22:15 -08:00
Daniel Rosenwasser 654975481f
Use spaces instead of non-breaking spaces, narrow non-breaking spaces. (#42500) 2021-02-03 14:29:42 -08:00
Andrew Branch 1c25b009f2
Sort import fixes by number of directory separators (#42614)
* Add failing test

* Sort all import fixes by number of directory separators
2021-02-03 10:42:13 -08:00
Andrew Branch 96cc9b96fe
Make object literal properties new identifier locations when not contextually typed (#42612)
* Make object literal properties new identifier locations when not contextually typed

* Fix completions after comma in object literal

* Update other test
2021-02-02 16:17:55 -08:00
Andrew Branch 9d21a5b56c
Fix indentation of multiline conditional expressions (#42484)
* Fix indentation of multiline conditional expressions

* Add more comment

* Fix comment typo

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* Fix suggestion formatting

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2021-01-29 12:07:57 -08:00
Andrew Branch 65e4d60d81
Fix formatter determination of initial indentation of list items after the first (#42352)
* Add failing test

* Fix determination of initial indentation of list items after the first
2021-01-29 09:49:47 -08:00
M.Yoshimura 701493fb80
Support top level "for await of" (#37424)
* Support Top Level "for await of".

* Add test cases for top level "for await of".

* Apply suggestions from code review

* add test cases

* remove redundant variables

* fix test baselines

* Update diagnostic message and tests

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-01-25 13:40:45 -08:00
Amin Pakseresht 290af69b73
Filter out global keywords of UMD module export declarations in completion providing auto import suggestions (#42141)
* Add AutoImportSuggestions for UMD module export declarations instead of global keywords

* Add test for scripts

* Add more comments

* Provide auto import suggestion only for modules and not scripts

* PR review #1

* PR review #1
2021-01-25 09:29:13 -08:00
chenjigeng d1e1e9dccc
Feat/exclude completions of variable initializers (#42087)
* feat: exclude declared variable when Object literal completions

* feat: check undeclareVariable when completion

* feat: add completion test case

* feat: code optimization

* feat: support shorthand property assignment

* feat: add shorthand property assignment test case

* feat: update completionPropertyShorthandForObjectLiteral test cases

* feat: exclude completions of variable initializers

* feat: update test cases

* feat: add completionListWithoutVariableinitializer test case

* feat: perfect the completionListWithoutVariableinitializer test case

* feat: remove isIdentifier limit

* feat: update test cases

* feat: code optimization and filter out some binding cases

* feat: update test case

* feat: handle arrow function expressions without braces

* feat: add arrow function expressions without braces test case

* feat: check node.parent exist first

* feat: optimization name

* feat: optimize test cases

* chore: code formatting

* feat: perfect type
2021-01-15 15:57:18 -08:00
Oleksandr T 8324dec9e9
feat(33715): include methods of class defined in a property (#42164) 2021-01-15 09:52:46 -08:00
Oleksandr T c83f769850
fix(41405): allow using property access as reference to function (#41429) 2021-01-14 17:02:48 -08:00
Andrew Branch 33ea6c581a
Fix indentation for closing > of ExpressionWithTypeArguments (#42341) 2021-01-14 14:48:40 -08:00
Oleksandr T 8eaf58fd13 fix(42259): omit merging modules with different names 2021-01-14 15:27:28 +02:00
Oleksandr T 0c58edeb29
feat(26217): Add missing member fix should work for missing function (#41215)
* feat(26217): Add missing function declaration QF

* use codeFixAvailable instead of codeFix

* add diagnostics messages 'Method not implemented.' and 'Function not implemented.'

* use codeFixAvailable instead of codeFix

* fix signature types
2021-01-08 16:10:50 -08:00
Sheetal Nandi 66ba15a3fd
If import is used in the file, prefer that import specifier over calculating new one (#42224)
* Test case where the wrong path is emitted

* If import is used in the file, prefer that import specifier over calculating new one
Fixes #39117

* Update Baselines and/or Applied Lint Fixes

* When non-relative path is used as user preference, ignore relative paths even if they are from the existing file

* Fix test

* Add comment

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2021-01-08 15:20:29 -08:00
Orta Therox 055f363fba
Reverts #39277 removing bundledPackageName (#41499)
* Reverts #39277

* Bring back modeyule resolution for the test runner
2021-01-08 10:55:34 +00:00
Oleksandr T 042bf4eb15
feat(14248): add returns tag to JSDoc template (#42068) 2021-01-07 17:57:23 -08:00
Ron Buckton 0d284e6c26
Add support for abstract constructor types (#36392)
* Add support for abstract constructor types

* Add backwards-compatible overloads for creating/updating constructor types

* Reverting use of 'abstract' in lib/es5.d.ts due to eslint issues

* Update baseline due to reverting lib

* Add error for failing to mark an mixin class as abstract

* Fix declaration/quick info for abstract construct signatures
2021-01-07 17:11:14 -08:00
Song Gao b9ac2f50b8
remove duplicated type -- remove TriviaKind, keep TriviaSyntaxKind. (#42108) 2021-01-04 14:34:53 -08:00
Oleksandr T f1dca6a61f
fix(42019): include the jsdoc tags from the base declaration (#42098) 2021-01-04 15:33:26 +00:00
chenjigeng ea93ee6db9
fix: host.isKnownTypesPackageName maybe undefined (#42050)
* fix: host.isKnownTypesPackageName maybe undefined

* feat: remove GH#18217 comment
2020-12-30 12:13:56 -08:00
Oleksandr T dfe23421ba
fix(41867): completions - omit the deprecated flag if some declarations are not deprecated (#41941) 2020-12-30 10:42:38 -08:00
chenjigeng ea03c2966b
Fix/jsx syntax quickinfo (#42124)
* feat: add jsx type invalid check

* feat: update jsxGenericQuickInfo test cases
2020-12-28 09:43:43 -08:00
Oleksandr T fe297df9df
fix(42034): allow convert async function with empty catch (#42123) 2020-12-28 09:34:28 -08:00
Jesse Trinity 8bbef818ed
Hierarchical refactorings (#41975)
* add hierarchical refactoring strings

* fourslash tests

* extractSymbol filters returned actions

* move refactorKind check to utilities

* rename parameters

* messaging for addOrRemoveBracesToArrowFunction

* fix up inferFunctionReturnType

* fix up convertArrowFunctionOrFunctionExpression

* add preferences to fourslash method

* fix up convert string

* fix up moveToNewFile

* fix lint errors

* remove extra arrow braces diagnostics

* break out tests

* add refactor helpers

* refactor refactors

* keep list of actions

* address PR comments

* response protocol

* address more comments
2020-12-23 12:50:03 -08:00
Andrew Branch c84838bd23
Avoid rewriting bare module specifiers on rename when fix is not verifiably correct (#41959) 2020-12-22 11:02:38 -08:00
orange4glace 1e4a5c9b37
fix(41259) : JS autocomplete doesn't work for object literal shorthands (#41539)
* fix: #41259

* fix: #41259

* fix: fourslash

* fix: remove nested if

* fix: change tc result for #41259

* fix: less restrictive shorthand completion rules

* fix: use typeMembers to find out whether properties are empty

* fix: typo

* fix: lint

* fix: exclude Object in completion

* fix: test

* fix: testcase tidy up

* fix: apply completions for unclosed literal and missing comma

* fix: ignore auto-imports

* fix: use exact to ensure the order of completions

* fix: use exact to ensure the order of completions

* fix: add new lines so it can easy to be distinguished
2020-12-22 10:36:52 -08:00
Andrew Branch 487be36919
Fix auto import completion inserting wrong module specifier (#41955)
* Don’t look for reëxports when import source was an ambient module

* Add additional assertion for clarity
2020-12-18 15:13:02 -08:00
Andrew Branch 49136f7879
Use getPropertiesForObjectExpression in string literal object completions (#42020)
Co-authored-by: Johanne Enama <jenama@users.noreply.github.com>
Co-authored-by: Kevin Wong <kwong0419@users.noreply.github.com>

Co-authored-by: Johanne Enama <jenama@users.noreply.github.com>
Co-authored-by: Kevin Wong <kwong0419@users.noreply.github.com>
2020-12-18 14:20:41 -08:00
Song Gao 8cbc576954
Fix #41800 correctly. (#41895)
* fix as suggestion.

* Update moduleSpecifiers.ts

* compare symbol rather than string

* fix typo.

* fix

* fix lint.

* better name and more clear code

* fix comment.

Co-authored-by: Orta Therox <git@orta.io>
2020-12-16 18:56:18 -08:00
Wesley Wigham b869c9cffa
Add text-based fastpaths into LS token matching (#41924)
* Add text-based fastpaths into LS token matching

* Update src/services/utilities.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Update src/services/utilities.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Update src/services/utilities.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Limit search a bit

* Secretly, this was allowed to be `undefined` and was in fact used as such

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2020-12-15 15:40:48 -08:00
Léo Meira Vital 4a9e2be386
fix(41868): Infer parameter from usage does not work on arrow functions that are a PropertyDeclaration of a Class (#41869) 2020-12-14 17:08:52 -08:00
Andrew Branch 78ded6577e
Make findAllReferences work on triple-slash reference paths that resolve to scripts (#41936)
* Support find-all-references on triple-slash references that resolve to scripts

* Rename terrible name

* Add test for <reference types="..." />

* Actually accept baselines
2020-12-11 15:46:11 -08:00
Andrew Branch 9dfbf07d8a
Find references of a module by filename (#41805)
* Naive implementation enough to build and write a test

* Add simple test

* Add project references test

* Add deduplication test, accept baselines

* Add test for referencing a script (doesn’t do anything)

* Update API baselines

* Use refFileMap for non-module references

* Fix find-all-refs on module specifier

* Remove unused util

* Don’t store text range on ts.RefFile

* Ensure string literal could itself be a file reference

* Remove unused utilities

* Improve baseline format

* Preserve old behavior of falling back to string literal references

* Update baselines from master

* Fix old RefFileMap code after merge

* Add test for additional response info

* Undo test change
2020-12-11 12:37:02 -08:00
Oleksandr T 1c1cd9b08d
fix(37539): extend scope for function expressions to include JSDoc (#41364) 2020-12-11 09:00:05 -08:00
Oleksandr T 0fa41db6c6
fix(41827): allow infer parameters from method signature usage (#41836) 2020-12-07 14:00:46 -08:00
Oleksandr T 2946318df0
fix(41526): add JSDoc type annotations before parameters (#41561) 2020-12-04 16:52:12 -08:00
kingwl 870f5b613a Merge branch 'master' into noPropertyAccessFromIndexSignature_fix 2020-12-04 12:47:38 +08:00
Andrew Branch 69bc3f3b0c
Allow type-only imports on ImportEqualsDeclarations (#41573)
* Allow type-only ImportEqualsDeclarations

* Suppress CJS-in-ESM error when type-only

* Add grammar error on import type in import alias

* Update API baselines

* Fix importsNotUsedAsValues with ImportEqualsDeclarations

* Make bad error talk words more good for Daniel. Fixes #41603

* One more error message baseline update

* Update transformer and emitter
2020-12-03 13:27:15 -08:00
kingwl 501b69c61f respect quote Preference 2020-12-03 12:00:30 +08:00
Jack Works 0b6c9254a8
Fix import tracker for dynamic import (#41473)
* chore: migrate findAllRefs_importType_js to baseline

* fix: reference for dynamic import

* fix: find all reference for typeof import()

* fix: test

* refactor: addIndirectUser

* refactor: isExported

* refactor: isExported

* resolve review
2020-12-02 14:46:20 -08:00
Ryan Cavanaugh 9a957e7b9c
Remove incorrect assert that triggers crash on completions of globalThis (#40278)
Fixes #39338
2020-12-02 11:47:32 -08:00
Armando Aguirre fd50f1e3c9
Merge pull request #41543 from a-tarasyuk/fix/41534
fix(41534): Maximum call stack error while computing document symbol file
2020-12-01 18:03:11 -08:00
Wenlu Wang 55810095f4
Allow qualified name for convert namespace import (#41592) 2020-12-01 15:23:57 -08:00
inokawa d57954345b
Fix typos (#41723) 2020-12-01 13:46:41 -08:00
Oleksandr T 23b3eb685f
fix(41621): fixUnusedIdentifier - allow deleting prefix/postfix unary operators (#41624) 2020-11-30 13:58:47 -08:00
Oleksandr T 1bd8e388ae
fix(41688): completions with infer keyword (#41704) 2020-11-30 11:56:12 -08:00
Song Gao d5779c75d3
replace whole path if directory separator appears for import completion. (#41412)
* replace whole path if directory separator appears.

* Fix.

* revert change.

* Fix test case.

* add test.

* fix as suggested.

* revert useless change

* adapt to code change.

* fix baseline for test file.
2020-11-25 09:37:08 -08:00
Andrew Branch 3fa30f4826
Remove obsolete go-to-definition code after CommonJS alias changes (#41522)
* Remove obsolete code

* Revert package-lock change
2020-11-25 09:01:56 -08:00
Oleksandr T 5adb55eb18
feat(41216): show JSDoc for aliases (#41452) 2020-11-24 14:40:51 -08:00
Oleksandr T 03877260f8
fix(41194): ignore jsxFrag identifier in import declarations (#41441) 2020-11-24 14:29:47 -08:00
Jean Pierre 71559a5c0c
Fix show deprecated suggestion for alias (#41128)
* Fix show deprecated suggestion for alias

* Fix failing tests

* Avoid duplicated kind modifiers
2020-11-23 15:50:12 -08:00
Nathan Shively-Sanders d057f7a992
Remove-unused-identifiers codefix skips assigned identifiers (#41168)
* Remove-all-unused-identifiers skips assigned identifiers

Previously, fixUnusedIdentifier worked the same in fix-all mode as for a
single fix: identifiers with assignments would be deleted:

```ts
function f(a) { }
f(1)
```

becomes

```ts
function f() { }
f()
```

But any kind of argument will be deleted, even one with side effects.
For a single codefix invocation, this is probably OK.
But for fix-all, this could lead to multiple changes
spread throughout a large file.

Now fix-all will only delete parameters and variable declarations with
no assignments:

```ts
function f(a) { }
function g(a) { }
f(1)
g
let x = 1
let y
```

becomes

```
function f(a) { }
function g() { }
f(1)
g
let x = 1
```

* Don't remove assigned parameters for single codefix either

* add optional parameter test case

* Skip initialised params and binding elements

Based on PR feedback from @amcasey

* fixAll removes unused binding patterns completely

* Fixes from comments

Thanks @amcasey for the thorough review

* fix trailing space lint

* correctly remove-all array binding
2020-11-21 09:57:17 -08:00
Oleksandr T 9bcbca4e6c fix(41534): fix children circular references 2020-11-20 22:41:12 +02:00
Nathan Shively-Sanders d3abd35428
Unused Identifier codefix better understands constructors and methods (#41555)
* Unuse Identifier codefix understands constructors

Previously, it did not look for `super()` and `new this()` calls when
determining whether a constructor parameter could be deleted.

* better names, fix off-by-1 bug

* Codefix understands super methods now too

This unifies the code, changing it considerably.
2020-11-18 11:19:43 -08:00
Andrew Casey 79ffd03f8b
Add tracing support to tsserver (#41374)
* Add tracing support to tsserver

Read the `TSS_TRACE` environment variable to determine which directory
trace files should be written to.

Notable changes from tsc tracing:
1) Drop all tracepoints that depend on type IDs
2) Write output to trace.PID.json
3) New, server-specific events (request/response, cancellation, etc)

* Drop try-finally blocks that aren't strictly necessary

* Fix lint error

* Trace background work (for diagnostics)

* Move try-finally blocks into session so tsc doesn't use them

* Add missing try-finally

* Use consistent capitalization

* Inline canPop call where underlying variable is available

* Clarify comments

* Include PID in build-mode file names

* Introduce more efficient popAll function

* Trace throwIfCancellationRequested rather than isCancellationRequested

* Remove unnecessary try-finally blocks

* Add a command-line argument for consistency with logging

* Fix rebase issues

* Address PR feedback

* Rename completionEvents to eventStack

* Drop assertStackEmpty as hard-to-maintain and marginally valuable

* Rename stepCancellation to stepCanceledEarly

* Rename stepEarlyCancellation to stepCanceled and use flag instead

* Check correct variable on exit
2020-11-16 09:26:28 -08:00
Andrew Branch 266d8de64a
Proposal: importModuleSpecifierPreference: project-relative (#40637)
* Add new importModuleSpecifierPreference value

* Add second test

* Update API baselines

* Clean up and add some comments

* Rename option value
2020-11-11 11:48:32 -08:00
Wenlu Wang ca7510ea05
String literal rename support (#39298)
* add basicly support for rename string literal type

* fix merge conflict

* fix some behavior

* Update package-lock.json

* Update package-lock.json

* do not break old behavior if not type checked

* fix cr issue

Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
2020-11-06 09:58:34 -08:00
Oleksandr T 899e2d00e9
fix(40469): suggest QF convert 'Convert to named function' to function expressions (#40476) 2020-11-05 10:25:24 -08:00
Oleksandr T 98aaeb7f48
fix(40610): handle template string concatenation (#40653) 2020-11-05 10:09:21 -08:00
Oleksandr T 09048656d2
feat(40750): add refactoring to infer a return type annotation to a function (#41052) 2020-11-03 16:22:13 -08:00
Oleksandr T ad70313141
fix(39858): generate valid async/await code for imported functions (#40154) 2020-11-02 16:12:08 -08:00
Oleksandr T 5d81b17d02
fix(40042): add modifiers in correct position for decorated methods (#40050) 2020-11-02 15:52:57 -08:00
Oleksandr T e4c1568c5d
fix(41078): add element access expressions support in convertFunctionToEs6Class (#41089) 2020-11-02 15:49:22 -08:00
Oleksandr T 3f92a6498f
fix(40257): fix type parameters range (#40265) 2020-11-02 15:20:13 -08:00
Wenlu Wang ce8d702586
Add support for pedantic property access (#40171)
* Add support for pedantic property access

* accept baseline

* Update diag message

* Avoid pedantic

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-11-02 15:19:00 -08:00
Nathan Shively-Sanders ae81add083
Separate delete-all-imports from other delete-all (#41105)
This fixes the first part of #32196
2020-11-02 14:18:50 -08:00
Oleksandr T eb6ddf6b29
fix(40671): suggest ConvertStringToTemplateLiteral refactoring for string with property/element acceses elements (#40942) 2020-10-29 15:23:11 -07:00
Michael 71cd5d522d
Fix two issues with ConvertToTypeOnlyExport codefix (#40490)
* Modify test case to reproduce error

* Fix TypeOnlyExport codefix to work with 3 or more type exports in the same declaration

The check to ensure that a fixed export declaration wasn't fixed again
was reversed. This only surfaced when 3 or more type exports existed in
the same declaration.

* Add failing test cases for comments being duplicated

* Fix convertToTypeOnlyExport codefix from duplicating leading comments

* Simplify convertToTypeOnlyExport when change is just inserting `type` keyword

Co-authored-by: Andrew Branch <andrew@wheream.io>
2020-10-27 15:08:20 -07:00
Oleksandr T 9ed608b439
fix(41244): ignore synthesized imports (#41267) 2020-10-27 13:22:02 -07:00
Oleksandr T 3754bb4455
fix(40994): change type for optional properties (#41011) 2020-10-27 10:05:40 -07:00
Alex T 417b8a9481
fix(29881): infer quote preference for property access conversion in completions (#41041) 2020-10-13 10:06:27 -07:00
Andrew Branch 83d02a5f05
Fix auto imports for export default edge cases (#41068) 2020-10-12 15:42:58 -07:00