3795 Commits

Author SHA1 Message Date
Alexander T
9f3af67929
fix(10019): allow renaming labels (#40064) 2020-08-18 01:04:49 -07:00
Nathan Shively-Sanders
c3d41bbb73
Alias for commonjs require in JS (#39770)
* First attempt at aliases for require

* test+initial support for const x=require

* 1st round of baseline improvements

* 2nd round of baseline updates

* support property access after require

* check @type tag on require

* forbid expando missing namespaces on aliases

taken from #39558 as soon as it was created

* accept error baselines that are good, actually

* Scribbling on d.ts emit code

* use getSpecifierForModuleSymbol

* hideous hack for module.exports of aliases

* Fix module.exports.x --> export list emit

* fix isLocalImport predicate

* require only creates aliases in JS

* re-handle json imports

* update fourslash baseline

* Cleanup in the checker

1. Simplify alias resolution.
2. Simplify variable-like checking.
3. Make binding skip require calls with type tags -- they fall back to
the old require-call code and then check from there.

I haven't started on the declaration emit code since I don't know what
is going on there nearly as well.

* Function for getting module name from require call

* First round of cleanup plus a new test

Found one missing feature, not sure it's worth adding.

* more small cleanup

* more cleanup, including lint

* use trackSymbol, not serializeTypeForDeclaration

* Code review comments, plus remove unneeded code

Ad-hoc type reference resolution for `require` isn't needed anymore.

* find all refs works

* remove old ad-hoc code

* make it clear that old behaviour is not that correct

* update api baselines

* remove outdated comment

* PR feedback

1. Fix indentation
2. Add comment for exported JSON emit
3. Add test case for nested-namespace exports.

* add a fail-case test (which passes!)
2020-08-17 14:00:37 -07:00
Zen
0ed523bb60
fix jsx completions after attributes (#39859)
closes #39530
2020-08-13 16:14:12 -07:00
Eli Barzilay
620e260576 Avoid the double-symbol trick for enums
Nameless jsdoc typedefs have their exportedness controlled by the
exportedness of the location they pull their name from.

Fixes #33575.
2020-08-12 18:40:57 -04:00
Wenlu Wang
57e2fe0462
Improve deprecated suggestion node position (#39702)
* Improve deprecated suggestion node position

* fix typo

* Simplify code

* merge helper function
2020-08-10 17:37:11 -07:00
Nathan Shively-Sanders
3328fdb2d8
Use isUncalledFunctionReference for aliases too (#39950)
* Use isUncalledFunctionReference for aliases too

Fixes bogus deprecated notices on imports of functions with deprecated
overloads, but with some non-deprecated overloads.

Fixes microsoft/vscode#104238

* Just check all declarations, don't call isUncalledFunction
2020-08-07 10:07:55 -07:00
Jesse Trinity
91a7c359b3
Insert auto imports after header comment (#39924)
* place first import after header

* don't insert before non-header
2020-08-06 13:33:29 -07:00
Andrew Branch
7f4e1b699a
Find tagless JSDoc as preceding token (#39912) 2020-08-05 10:09:45 -07:00
Nathan Shively-Sanders
c9f05af2c8
Merge pull request #37891 from Neonit/jsDocIndentationPreservation
Fix indentation preservation in JSDoc (#37717)
2020-08-04 16:09:50 -07:00
Orta Therox
faf128de15
Fix formatting scanner on JSX text that looks like trivia (#39718)
* Fix formatting scanner on JSX text that looks like trivia

* Combine if statements

Co-authored-by: Andrew Branch <andrew@wheream.io>
2020-07-30 13:56:14 -04:00
Sheetal Nandi
48e58f44db
Handle unresolved baseType when trying to get completions for static member (#39731)
* Handle unresolved baseType when trying to get completions for static member
Fixes  #38067

* Update src/services/completions.ts

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

* correct the condition

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-07-24 16:37:28 -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
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
Song
e76d17257a
Fix 38219: signature helper works for optional function condition. (#39672)
* fix optional fuction condition.

* Adds a test

Co-authored-by: Orta <git@orta.io>
2020-07-22 12:30:21 -04:00
Song
294a0406e3
not escape unicode char for import path string. (#39463)
* not escape unicode char for import path string.

* fix test.
2020-07-22 11:28:29 -04:00
Song
d897646a4a
fix 39453 (#39579)
* fix 39453

* add restriction.

* add tests

* comment.

* fix as suggestion.
2020-07-21 09:40:25 -07:00
Alexander T
6430211f8f
fix(38868): add separator for type parameters (#39621) 2020-07-16 10:58:16 -07:00
Wenlu Wang
fcd4fcb3d7
Use combined node flags (#39403) 2020-07-15 09:22:12 -07:00
Wenlu Wang
7b728754c0
Fix incorrect deprecated mark (#39611)
* Fix incorrect deprecated mark

* improve test
2020-07-15 08:47:25 -07:00
Alexander T
ececf3b0a7
fix(33511): show jsx namespace default import quick fix if it does not exists in the current scope (#38419) 2020-07-14 15:43:18 -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
Armando Aguirre
6279f981b3
Merge pull request #37029 from armanio123/AddToggleCommentFeature
Add ToggleLineComment and ToggleMultilineComment service
2020-07-13 17:48:50 -07:00
Andrew Branch
3c91133f97
Fix find-all-references on undefined (#39591)
* Fix find-all-references on `undefined`

* Show references in input files in baseline

* Inline commentEachLine

* firstOrUndefined doesn’t take undefined
2020-07-13 17:21:16 -07:00
Armando Aguirre
0d38f09e36 PR comments and minor bugs 2020-07-10 17:44:02 -07:00
Armando Aguirre
ef81a0d0ee Merge remote-tracking branch 'upstream/master' into AddToggleCommentFeature 2020-07-09 21:55:36 -07:00
Armando Aguirre
b81f240e96 PR comments 2020-07-09 18:35:54 -07:00
Sheetal Nandi
b397d1fd4a
Fixes searches for export * as 'identifier' (#39533)
* Fixes searches for export * as 'identifier'
Fixes #39006

* Fix the context span to export declaration (was incorrectly set to sourceFile in prev commit)
2020-07-09 13:45:43 -07:00
ShuiRuTian
bf1ea6508b
fix static method reference non-static (#38730)
* fix static method reference non-static

* fix contextRangeIndex

* fix lint.

* fix style.

* update according to suggestion.

* continue fix.

* use every rather than foreach

* format

* fix

* add comment.

* fix according to review suggestions.

* Update src/services/findAllReferences.ts

* Update src/services/findAllReferences.ts

* Update src/services/findAllReferences.ts

* Update src/services/findAllReferences.ts

* Update src/services/findAllReferences.ts

Co-authored-by: Song Gao <song.gao@laserfiche.com>
Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-07-09 12:21:12 -07:00
Jesse Trinity
8e9de9bed2
Fix39458 (#39508)
* remove undefined from optional parameter

* accept baselines

* use getTypeWithFacts
2020-07-09 11:17:18 -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
Alexander T
48c19eebaf
fix(25155): add space before optional parameters/properties (#38798) 2020-07-08 13:38:15 -07:00
Sheetal Nandi
0f86c04af3
Fixes searches for symbols exported using export * as (#39507)
Fixes #39006
2020-07-08 13:31:21 -07:00
Alexander T
ebac7ec08f
fix(39421): omit prefix text for rest binding element (#39433) 2020-07-08 13:25:28 -07:00
Alexander T
8795458d6d
fix(39440): show QF for abstract classes with methods which include 'this' parameter (#39465) 2020-07-08 12:36:42 -07:00
Nathan Shively-Sanders
53a756ea63
Type this in more constructor functions (#39447)
* Type `this` in more constructor functions

Previously,  `this: this` in constructor functions only when there was
an explicit `@constructor` tag on the function. Now, `this: this` for
any function that's known to be a constructor function.

This improves completions inside constructor functions; also note that
previously the compiler *did* type `this: this` inside methods of constructor
functions, so this fix makes us more consistent. This is reflected in
the large number of baselines that improve.

The fix is a simple switch to `isJSConstructor`, which is the standard
way to detect constructor functions. I'm not sure why the original PR
didn't use this method.

I remember discussing this limitation in the original bug, #25979, and
I guess I decided that it made sense. But I was heavily primed by the bug's
framing of the problem in terms of `noImplicitThis`, which *should*
require an explicit `@constructor` tag.

With better typing comes better detection of `@readonly` assignment; I
had to fix the readonly detection code to use `isJSConstructor` as well.

* Remove `Add @class tag` fix for noImplicitThis.

The new rules mean that it never applies. It's possible that it should
apply to functions like

```js
function f() {
  this.init()
}
```

In which `init` is never defined, but I think this program is incomplete
enough that not offering the fix is fine.

* Fix precedence of `@this`

Previously, both `@class` and `@this` in a jsdoc would cause the `@this`
annotation to be ignored. This became a worse problem with this PR,
because `this` is correctly typed even without the annotation.

This commit makes sure that `@this` is checked first and used if
present.
2020-07-08 08:44:17 -07:00
Wesley Wigham
62b4377acf
Fix test semantic merge conflict between #39348 and #39130 (#39478) 2020-07-07 14:30:58 -07:00
Andrew Branch
0c75021860
Process type nodes in codefixes/refactors for auto-imports recursively (#39130)
* Process type nodes for auto-imports recursively

* Rename function
2020-07-07 13:11:23 -07:00
Nathan Shively-Sanders
1814e2a5c4
Mark @typedef as a type declaration (#39468)
* Mark @typedef as a type declaration

This is only important right now for marking uses of deprecated tags due
to the way that deprecated type references are computed. But I'm
surprised it hasn't caused problems elsewhere.

Fixes #39466

* Also mark @callback and @enum

Requires making name lookup in isTypeDeclarationName smarter, but this
is only used by services, so shouldn't be too performance sensitive.
2020-07-07 10:37:52 -07:00
Alexander T
6b493f2048
fix(23871): change insertNodeAfter to replaceNode to avoid extra newlines (#38045) 2020-07-07 12:54:03 -04:00
Alexander T
2a92a6ea91
fix(39332): handle quotes preference in interface method signatures (#39348) 2020-07-06 17:00:35 -07:00
Wenlu Wang
453365284c
Avoid check for union keys (#39314) 2020-07-06 15:01:05 -07:00
Daniel Rosenwasser
77bf2045d8
Merge pull request #39379 from a-tarasyuk/bug/39346
fix(39346): Intelligent code completion not working in child class with composited base interface
2020-07-06 11:59:30 -07:00
ShuiRuTian
f29e03eea5
autocomplete works for const assertion. (#39412)
* fix 39384

* add test
2020-07-06 08:49:50 -04:00
Nathan Shively-Sanders
93ccc17658
Node-based @deprecated checks (#39323)
* Node-based @deprecated checks

Switch the checker to syntactic checks for `@deprecated` on
declarations. This requires a bit more checking of declarations in the
checker at times, but it

1. Gets rid of work, and a symbol flag, in the binder.
2. Skips work in the checker unless there is a `@deprecated` tag.
3. Makes it fairly simple to only issue errors on particular signatures
   of overloaded functions.

* remove in-progress comment

* remove unused isTypeDeclaration

* ❤️ lint

* support jsx and tagged template functions

* Support decorators too
2020-07-02 14:09:59 -07:00
Alexander T
d137e4a23b fix(39346): show completion in inherited classes from the composited base interface 2020-07-02 11:40:17 +03:00
Nathan Shively-Sanders
df5981319f
Fix crash on completion in jsdoc namepath (#39347)
contextToken may be undefined, so the isAssertionExpression call in
filterGlobalCompletion needs to check for undefined.
2020-06-30 15:53:13 -07:00
Andrew Branch
e2c5a90cc3
Disable signature help on unresolved bare identifiers; add more declaration info on other unresolved calls (#39352)
* Disable signature help on unresolved bare identifiers; add more declaration info on unresolvedproperty access

* Remove stray ts-ignore
2020-06-30 14:25:27 -07:00
Alexander T
8b6a88700e
fix(32297): add quick-fix action to delete parameter destructuring elements (#38764) 2020-06-30 11:44:47 -07:00
Daniel Rosenwasser
1bbd5ef36b
Merge pull request #38754 from a-tarasyuk/feat/25259
feat(25259): Better error report for equals instead of colon in object literals
2020-06-30 01:56:26 -07:00
Alexander T
21a26ca08a feat(25259): add better error to report for equals instead of the colon in object literals 2020-06-30 10:33:56 +03:00