Commit graph

409 commits

Author SHA1 Message Date
Andrew Branch 7a0f603b11
Fix extract symbol crash on unterminated literals; don’t offer to extract export = ... (#40272)
* Don’t offer to extract export assignment

* Terminate unterminated literals when extracting them

* Add test with regular expression ending in backslash

* Add test for string literal ending in backslash

* Remove unused parameter default
2020-08-31 14:17:09 -07:00
Andrew Branch b834096998
Fix emit/formatting issues in refactors (#39506)
* Fix #37948

* Fix formatter skipping tab/space fixup on comments, handle trailing commas in list closing line count.

Fixes #37944

* Add newline between imports and main body of new file in moveToNewFile

Fixes #37941

* Update baseline (probably broken before?)
2020-07-22 10:31:42 -07:00
Jesse Trinity 17022388bd
Add refactor convertToOptionalChainExpression (#39135)
* add convertOptionalChain

* cover more cases

* expose containsMatchingReference

* clean up performing edits

* bound start position

* add tests

* refactor and handle edge cases

* update tests

* consider explicit requests for empty spans

* update fourslash to use trigger reason

* add tests cases for trigger reason

* fix errors

* remove type assertion

* fix non ampersand chains

* clean up some logic

* add ternary case

* add diagnostic message

* add nullish check for ternary expressions

* Update src/services/refactors/convertToOptionalChainExpression.ts

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

* Update src/services/refactors/convertToOptionalChainExpression.ts

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

* Update tests/cases/fourslash/refactorConvertToOptionalChainExpressionForTriggerReason3.ts

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

* Update tests/cases/fourslash/refactorConvertToOptionalChainExpressionForTriggerReason1.ts

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

* reformat and remove unused checks

* allow any for ternary refactor

* add tests

* add tests

* check return and variable statements

* use isMatchingReference instead of containsMatchingReference

* allow partial selections

* fine tune selection ranges

* recurse for call expressions

* fix spellings

* add recursive cases

* remove isOrContainsMatchingReference

* cleanup

* more refactoring

* cleanup

* rename tests

* address PR comments

* check match syntactically

* handle another call expression case

* some renames

* inline some checks

* add test

* address comments

* add refactorNotAvailableReason

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-07-13 19:33:33 -07:00
Ron Buckton 2c08affa0d
Merge pull request #39264 from microsoft/migrateMapsAndSets
Migrate maps and sets
2020-07-13 10:38:30 -07:00
Andrew Branch 03c79d7422
Insert auto-imports in sorted order (#39394)
* Sort auto-imports

* Avoid re-checking sort all the time

* Add comment
2020-07-08 15:25:04 -07:00
Ron Buckton 9d5cd280ef Merge branch 'master' into migrateMapsAndSets
# Conflicts:
#	src/compiler/checker.ts
#	src/compiler/commandLineParser.ts
#	src/compiler/core.ts
#	src/compiler/moduleNameResolver.ts
#	src/compiler/transformers/declarations.ts
#	src/compiler/tsbuildPublic.ts
#	src/compiler/types.ts
#	src/compiler/utilities.ts
#	src/harness/client.ts
#	src/server/editorServices.ts
#	src/server/typingsCache.ts
#	src/server/utilities.ts
#	src/services/codefixes/convertToAsyncFunction.ts
#	src/services/documentRegistry.ts
#	src/services/importTracker.ts
#	src/services/refactorProvider.ts
#	src/services/refactors/extractSymbol.ts
#	src/testRunner/unittests/programApi.ts
#	src/typingsInstallerCore/typingsInstaller.ts
#	tests/baselines/reference/api/tsserverlibrary.d.ts
#	tests/baselines/reference/api/typescript.d.ts
2020-07-07 13:53:46 -07:00
Ron Buckton 7b942b4fa8
Revert the type change to ts.Map (#39366) 2020-07-01 17:00:26 -07:00
Alexander T c75af697af fix(29890): wrap variable/method/property to jsx expression 2020-06-28 10:51:11 +03:00
Ron Buckton 611b77f2e6 Migrate more places to use Map/Set 2020-06-26 10:15:53 -07:00
Ron Buckton eb2f4e2337
Switch to ES Map/Set internally (#33771)
* Add full implemention of Map and Set to shims

* Update default Map interface

* Remove WeakMap/WeakSet

* Add tests for set shim

* Update most usages of Map<K, true> to Set

* PR Feedback

* Fix lint issues

* Change key in fsWatchCallback

* Simpler shim, more tests

* Fix typo in collection shim
2020-06-26 10:12:47 -07:00
Pranav Senthilnathan 2f793892f1
Add reason for a disabled code action (#37871)
* add reason for a disabled code action

* add addOrRemoveBracesToArrowFunction

* use user preferences

* add error reason

* accept baseline changes

* fix lint rules

* move messages to diagnosticMessages.json

* rename 'error' to 'notApplicableReason'

* accept baseline change

* address comments
2020-06-22 08:16:47 -07:00
Ron Buckton eb3645f16b
Refactor node factory API, use node factory in parser (#35282)
* Refactor node factory API, use node factory in parser

* Move UnparsedSource nodes to factory

* Make most Node properties read-only

* Make pos/end/parent and JSDoc 'comment' read-only

* Update function/constructor-type factories

* Remove treeStateObserver

* Simplify Debug.deprecate

* Remove unused factory methods, simplify lazy factory methods

* Fix base factory used for source file updates

* Update test baseline due to merge from master

* Rename factory methods to be more consistent (#39058)
2020-06-16 16:55:03 -07:00
Jesse Trinity 3b15b35b37
Merge pull request #38378 from jessetrinity/refactorTriggerReason
Add RefactorTriggerReason
2020-06-03 11:18:08 -07:00
Jesse Trinity d88ea4e1f8 address PR comments 2020-06-02 19:06:12 -07:00
Jesse Trinity 52dad733db
Merge branch 'master' into m-lambda-to-fn 2020-06-01 13:53:19 -07:00
Alexander T 68d2ee055c
fix(38815): dive in arrow functions to check only this usage instead of checking all statements (#38865) 2020-06-01 10:27:11 -07:00
Jesse Trinity ca58c0e03c fix merge conflicts 2020-05-29 14:04:07 -07:00
Jesse Trinity 06d2461cd0 convert import trigger reason only 2020-05-29 13:03:05 -07:00
Jesse Trinity a7c07d67d8 convert export cursor only changes 2020-05-29 13:02:57 -07:00
Jesse Trinity e565931392 fix up some bools 2020-05-29 13:01:33 -07:00
Jesse Trinity f3751fbdf3 change type of RefactorTriggerReason 2020-05-29 12:54:59 -07:00
Jesse Trinity 23f4dc9bd9 use enum for RefactorTriggerReason 2020-05-29 12:49:41 -07:00
Jesse Trinity f1127e6e94 extract symbol 2020-05-29 12:45:57 -07:00
Jesse Trinity 55880ee5e0 extractType explicitCursorRequest 2020-05-29 12:41:28 -07:00
Jesse Trinity 0296254a60 extractType 2020-05-29 12:41:22 -07:00
Jesse Trinity 1efcffc915 convertImport 2020-05-29 12:41:18 -07:00
Jesse Trinity c3828ed086 loosen convertExport conditions 2020-05-29 12:41:14 -07:00
Jesse Trinity 02fa39a6a9 enable explicit requests for addOrRemoveBracesToArrowFunction 2020-05-29 12:41:10 -07:00
Jesse Trinity bac046573f add trigger reason to protocol 2020-05-29 12:41:06 -07:00
BigAru fcb8e87e69 fix linting error 2020-05-27 20:47:02 +02:00
BigAru e6dc8f6c69 Merge remote-tracking branch 'upstream/master' into m-lambda-to-fn 2020-05-27 20:33:27 +02:00
Nathan Shively-Sanders 802e87b1eb Merge branch 'master' into always-error-on-property-override-accessor 2020-05-21 16:08:09 -07:00
Wesley Wigham 5f597e69b2
Support naming tuple members (#38234)
* Initial draft of named tuple members

* Show tuple labels and documentation in completions

* Swap allowed syntax to parameter-like

* Add quickfix for labeled tuple syntax mistakes

* Add refactoring to convert list of signatures to single overload

* Fix small bug in visitor verification

* Signature help for rest parameters which are unions of tuples are displayed as seperate entries now

* Expand sanity check test cases in conformance suite

* Add tests and code for preserving tuple names through spreads where possible

* More refactoring tests, some comment preservation and some fixed formatting of multiline tuples

* Handle missing parameter named in isValidDeclarationForTupleLabel

* Minor text fixes
2020-05-19 15:54:02 -07:00
Jack Works 7ec467e270
fix: extract const in jsx (#37912)
* fix: extract const in jsx

* Update src/services/refactors/extractSymbol.ts

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>

* Update src/services/refactors/extractSymbol.ts

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2020-05-19 14:29:49 -07:00
Alexander T 71711257ea
fix(33836): allow readonly modifier for a field with only get accessor (#36543) 2020-05-13 13:28:32 -07:00
Ron Buckton d07e866a28
Fix for jsdoc modifiers on constructor params (#38403)
* Fix for jsdoc modifiers on constructor params

* Update Public API baseline and fix unique symbol grammar check for js
2020-05-11 15:07:43 -07:00
Alexander T 738b6b5b68
fix(38073): hide 'Extract to function in global scope' action for arrow functions which use 'this' (#38107) 2020-05-11 12:25:25 -07:00
Eli Barzilay 29cf049e61 moveToNewFile: handle namespace imports too
Fixes #35591
2020-05-07 11:46:36 -04:00
Alexander T 5e0e254ef7
fix(38177): add auto-import for missing argument type in new functions/methods (#38213) 2020-05-04 12:37:04 -07:00
Andrew Branch 9569e8aaa4
Fix newline issues when adding multiple imports (#38119)
* Add new import declarations in a single TextChanges call

* Refactor
2020-04-23 11:59:38 -07:00
Joe Previte 583e70b3d1
fix(refactor): keep comments after refactor (#35937)
* add two tests: Refactor: Remove braces from arrow function

* refactor: simplify test and add another test

* fix: copyTrailingAsLeadingComments in addOrRemoveBracesToArrowFunction

* test: add additional test

* fix: clean up changes

* fix: add check for newEdit

* fix: add function for semi colon modifier

* feat: grab all comments during refactor

* refactor: update addOrRemoveBraces logic

* fix: remove duplicate function call

* Update src/services/refactors/addOrRemoveBracesToArrowFunction.ts

* remove blank line

remove blank line

Co-authored-by: Jesse Trinity <42591254+jessetrinity@users.noreply.github.com>
2020-04-15 11:06:04 -07:00
Nathan Shively-Sanders 4d541d2b74 Minor cleanup
1. Fix lint.
2. Make code easier to read.
3. Turns some asserts into bails instead.
2020-04-10 09:55:36 -07:00
Nathan Shively-Sanders 6eacc9c1e2 move into new, centrally (?) located file 2020-04-09 17:00:37 -07:00
Nathan Shively-Sanders e287c8321a Codefix invokes generate get-set accessor refactor
1. Add add-all test
2. Add codefix that delegates to get-set accessor refactor.

Needs massive amounts of cleanup and deduplication.
2020-04-09 15:06:45 -07:00
Andrew Branch 57f9076612
Remove extraneous string escape from convert to template string refactor (#37743)
* Add failing test

* Remove extraneous string escape

* Revert unnecessary change
2020-04-09 09:40:28 -07:00
Alexander T e897eb1b2a
fix(37817): omit comments in name accessor (#37822) 2020-04-07 16:59:54 -07:00
Wenlu Wang afc41f095d
Quick fix for functions lacking return expressions (#26434)
* stash

* add surmise for return type

* add support for more case

* add more test case

* add more testcase and fix all test

* fix changed diagnosis

* fix broken test case

* add more case

* rename quickfix

* fix conflict

* fix fix desc

* fix semi

* Avoid replace brace with paren

* Split fix all action

* Add return work in same line

* fix test cases

* rename baseline

* refactor and handle comment

* Support semi

* make helper internal
2020-04-02 10:06:14 -07:00
Andrew Branch 237ea526f9
Preserve newlines from original source when printing nodes from TextChanges (#36688)
* Allow emitter to write multiple newlines in node lists

* Progress

* Progress

* Fix recomputeIndentation

* Add tests, fix leading line terminator count

* Do a bit less work when `preserveNewlines` is off

* Fix accidental find/replace rename

* Restore some monomorphism

* Fix single line writer

* Fix other writers

* Revert "Fix other writers"

This reverts commit 21b0cb8f3b.

* Revert "Fix single line writer"

This reverts commit e535e279f9.

* Revert "Restore some monomorphism"

This reverts commit e3ef42743a.

* Add equal position optimization to getLinesBetweenRangeEndAndRangeStart

* Add one more test

* Actually save the test file

* Rename preserveNewlines to preserveSourceNewlines

* Make ignoreSourceNewlines internal

* Optimize lines-between functions

* Add comment;

* Fix trailing line terminator count bug for function parameters

* Preserve newlines around parenthesized expressions

* Back to speculative microoptimizations, yay

* Don’t call getEffectiveLines during tsc emit at all
2020-03-19 09:46:00 -07:00
Andy Hanson b0450aed56
Add codefix for --noImplicitThis (#27565)
* Add codefix for --noImplicitThis

* Code review

* Back to building post-merge

* Remove redundant functions + update tests

Infer-from-usage also inserts `this: any` parameters when needed, so I
removed that from fixImplicitThis.

Otherwise, fixImplicitThis has better suggestions than inferFromUsage,
so I moved inferFromUsage later in the suggestion order.

* More redundancy removal

Don't need to add `@this` anymore either since inferFromUsage will do
that.

* More baseline updates

From moving inferFromUsage down in priority I think?

* remove now-redundant ad-hoc jsdoc emit

* fix more bad merge

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-03-17 13:00:14 -07:00
Alexander T b41eb1bc61
feat(36249): add quick-fix action to declare a property as private which starts from underscore (#36632) 2020-03-13 10:33:56 -07:00