Commit Graph

3140 Commits

Author SHA1 Message Date
Wesley Wigham
96937fd592 Allow union signatures to merge when they have differing argument counts (#28604)
* Allow union signatures to merge when they have differing argument counts

* Accept updated baselines

* Adjust comments io changed tests
2018-11-19 17:05:28 -08:00
Sheetal Nandi
dc03115d14 Merge pull request #28585 from Microsoft/isTypeOnlyCompletion
Properly set symbolMeanings when calling getSymbolsInScope
2018-11-19 08:50:41 -08:00
Sheetal Nandi
eeaa8bb527 Merge pull request #28533 from Microsoft/generateGetAndSet_noFindAllRefs
generateGetAccessorAndSetAccessor: Don't use FindAllReferences
2018-11-19 08:47:12 -08:00
Andy Hanson
59c014ba32 Properly set symbolMeanings when calling getSymbolsInScope 2018-11-16 17:04:29 -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
Sheetal Nandi
6bb1ff2214 Merge pull request #27376 from Microsoft/codeFixCannotFindModule_suggestion_falsePositive
Don't implicit-any diagnostic for json module
2018-11-16 15:48:37 -08:00
Nathan Shively-Sanders
ea8ccc2ce4 In JS, constructor functions infer from call+construct (#28353)
* constructor functions infer from call+construct

Also fix an incorrect combining of inferences for rest parameters: the
inferred types will be arrays in the body of the function and the
arguments from outside the function will be the element type.

* All functions infer from call+construct contexts
2018-11-16 09:51:07 -08:00
Andy
b059135c51 When adding relative completions with rootDirs, still add completions for regular relative imports (#28561) 2018-11-15 15:11:27 -08:00
Nathan Shively-Sanders
6cee7c3080 Better nameless parameter implicit any error (#28554)
* Initial version, doesn't work for primitives yet.

Need to find out why.

* Primitives now work, plus improve error message

null and void don't even parse without parameter names so they are not
tested.

* Codefix: Add names to nameless parameters

* Improve error wording

* Add detail to error message
2018-11-15 12:45:39 -08:00
Andy
079f0436f3 Remove unused function (#28531) 2018-11-15 09:34:07 -08:00
Nathan Shively-Sanders
7a7328a17f string|number inferences are low priority (#28381)
* string|number inferences are low priority

Also, refactor unifyFromContext to explicitly handle priorities

* string/number/strnum are not mutually exclusive

* Assert that high/low can't apply to same element
2018-11-15 08:32:28 -08:00
Andy
2600250a24 Add 'bigint' to type keywords (#28537) 2018-11-14 22:18:05 -08:00
Daniel Rosenwasser
fe263708be Merge pull request #27019 from iliashkolyar/codefix_add_missing_new_operator
Codefix: add quick fix for missing 'new' operator
2018-11-14 16:53:25 -08:00
Andy Hanson
643678bb54 generateGetAccessorAndSetAccessor: Don't use FindAllReferences 2018-11-14 15:05:46 -08:00
Andy
da37457c72 When renaming an imported symbol, rename only in current file (#28406)
* When renaming an imported symbol, rename only in current file

* Improve re-export references

* Remember to use 'range' in for loop

* Uncomment tests
2018-11-14 09:09:00 -08:00
Wesley Wigham
004dc89600 Use elipses for reverse mapped types in nested positions (#28494) 2018-11-12 18:50:08 -08:00
Wesley Wigham
d99de73e85 Handle type argument lists as jsx completion starts (#28493)
* Handle type argument lists as jsx completion starts

* preceeding -> preceding
2018-11-12 16:30:04 -08:00
Wesley Wigham
2b345cc8f8 Track type recusion and symbol instantiation depth seperately in createAnonymousTypeNode (#28490) 2018-11-12 15:45:36 -08:00
Andy
fe1ba9bee3 Improvements to generateTypes (#28458)
* Improvements to generateTypes

* createProperty only if necessary
2018-11-12 11:50:48 -08:00
Anders Hejlsberg
a2205ad53d Merge pull request #28429 from Microsoft/fixEmptyObjectIntersection
Fix empty object intersections
2018-11-10 00:44:57 -08:00
Sheetal Nandi
d6df82a77c Merge pull request #28454 from Microsoft/codeFixAfterPrologue
Include code fix after prologue
2018-11-09 16:56:43 -08:00
Sheetal Nandi
c60ff902f1 Include code fix after prologue
Fixes #15515
2018-11-09 16:02:16 -08:00
iliashkolyar
047b76f979 Merge branch 'master' into codefix_add_missing_new_operator 2018-11-10 01:45:11 +02:00
Daniel Rosenwasser
02ca5bebbf Merge pull request #28340 from saschanaz/listindent-revive
List position based formatting
2018-11-09 15:34:16 -08:00
Daniel Rosenwasser
2585ccbe39 Merge pull request #28281 from ryanclarke/master
Add codefix for 'convert to unknown' diagnostic
2018-11-09 14:43:25 -08:00
Andy
c0e5c80e53 Add exports of current module to getSymbolsInScope (#28442) 2018-11-09 12:48:10 -08:00
Andy
aaf1d8055b Support finding references at module in module.exports = or export in export = (#28221)
* Support finding references at `module` in `module.exports =` or `export` in `export =`

* Add json test
2018-11-09 09:38:45 -08:00
Markus Wolf
6bd298b884 add test for remove modifier and parameter 2018-11-09 09:45:12 +01:00
Markus Wolf
13e85ac3a9 add more modifiers 2018-11-09 09:45:12 +01:00
Markus Wolf
d411fa34a7 Add test case for codeFix 2018-11-09 09:45:11 +01:00
Kagami Sascha Rosylight
7995f9153a apply suggested changes 2018-11-09 11:26:58 +09:00
Sheetal Nandi
b534fb4849 Merge pull request #27980 from EECOLOR/leading-slash-imports
match leading slash imports with path mappings - fixes #13730
2018-11-08 09:20:45 -08:00
Anders Hejlsberg
e95ed29ca9 Fix fourslash test 2018-11-08 18:02:04 +01:00
Ryan Clarke
ecb88f5a3e Fix comments on pull request 2018-11-07 21:43:02 -05:00
EECOLOR
1a9c20949e path mappings now supports rooted disk paths and urls - fixes #13730 2018-11-07 22:19:04 +01:00
Daniel Rosenwasser
41d3f0ad57 Merge pull request #28071 from pesca/improveCodeFix
Improve code fix for missing members
2018-11-06 11:29:51 -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
Nathan Shively-Sanders
4cb210ce2e Parameters infer from body and call sites (#28342)
* Parameters infer from body usage and call sites

* Function expressions infer from variable decl usages

If the function expression is the initialiser of a variable declaration.

* Update isApplicableFunctionForInference too

* Update baseline
2018-11-05 11:29:16 -08:00
Kagami Sascha Rosylight
8ed21a8a6a adjust test: always indented inside a list 2018-11-05 21:45:19 +09:00
Kagami Sascha Rosylight
7bc40cead8 indent size 8 based on list startline indentation 2018-11-05 21:45:19 +09:00
Kagami Sascha Rosylight
c6174f6914 resolve TODO 2018-11-05 21:45:19 +09:00
Kagami Sascha Rosylight
90d5413ccb tests 2018-11-05 21:45:19 +09:00
Nathan Shively-Sanders
ce85ee5115 Move infer-from-usage earlier in codefix list (#28318)
This makes it appear before the ts-ignore codefix, specifically.
2018-11-02 15:39:27 -07:00
Andy
4e59096ea5 Exclude keywords from import completions (#28114)
* Exclude keywords from import completions

* Still allow contextual keywords

* Add excludes tests
2018-11-02 14:33:02 -07:00
Nathan Shively-Sanders
a682a525b8 module.exports aliases have correct flags (#28303)
* module.exports aliases have correct flags

They are marked both as (1) alias and (2) assignment declaration. This
fixes alias resolution in cases where multiple module.exports
assignments exist, but differ in whether they are aliases or not:

```js
function f() { }
module.exports = f
module.exports = 23
```

Previously, this construct would fail to resolve the alias `f` because
the `export=` symbol would be marked as Alias | Value but not
Assignment. This change just adds Assignment so that the assignment
declaration alias-following rules apply: you should always follow the
alias, regardless of other flags.

Also, isAliasSymbolDeclaration needed to be tightened up. Previously, I
missed the condition that `module.exports =` aliases required an
EntityNameDeclaration on right-hand-side, just like `export default` and
`export =` aliases.

* Address PR comments

1. Rename test to be more accurate.
2. Always mark module.exports assignments with SymbolFlags.Assignment.
2018-11-02 09:08:04 -07:00
Nathan Shively-Sanders
8056e2b12f infer from usage's unification uses multiple passes (#28244)
* infer from usage's unification uses multiple passes

Previously, the unification step of infer-from-usage codefix would stop
as soon an answer was found. Now it continues if the result is
*incomplete*, with the idea that later passes may provide a better
inference.

Currently, an *incomplete* inference is

1. The type any.
2. The empty object type `{}` or a union or intersection that contains
`{}`.

In the checker, any takes priority over other types since it basically
shuts down type checking. For type inference, however, any is one of the least
useful inferences.

`{}` is not a good inference for a similar reason; as a parameter
inference, it doesn't tell the caller much about what is expected, and
it doesn't allow the function author to use an object as expected. But
currently it's inferred whenever there's an initialisation with the
value `{}`. With this change, subsequent property assignments to the
same parameter will replace the `{}` with a specific anonymous type. For
example:

```js
function C(config) {
  if (config === undefined) config = {};
  this.x = config.x;
  this.y = config.y;
  this.z = config.z;
}
```

* Unify all passes of inference from usage

In the previous commit, I changed inference from usage to continue
inference if a the result was *incomplete*. This commit now runs all 4
inference passes and combines them in a unification step. Currently the
unification step is simple, it:

1. Gathers all inferences in a list.
2. Makes properties of anonymous types optional if there is an empty
object in the inference list.
3. Removes *vacuous* inferences.
4. Combines the type in a union.

An inference is *vacuous* if it:

1. Is any or void, when a non-any, non-void type is also inferred.
2. Is the empty object type, when an object type that is not empty is
also inferred.
3. Is an anonymous type, when a non-nullable, non-any, non-void,
non-anonymous type is also inferred.

I think I might eventually want a concept of priorities, like the
compiler's type parameter inference, but I don't have enough examples to
be sure yet.

Eventually, unification should have an additional step that examines the
whole inference list to see if its contents are collectively
meaningless. A good example is `null | undefined`, which is not useful.

* Remove isNumberOrString

* Unify anonymous types

@andy-ms pointed out that my empty object code was a special case of
merging all anonymous types from an inference and making properties
optional that are not in all the anonymous type. So I did that instead.

* Use getTypeOfSymbolAtLocation instead of Symbol.type!

* Unify parameter call-site inferences too

Because they still have a separate code path, they didn't use the new
unification code.

Also some cleanup from PR comments.

* Add object type unification test

Also remove dead code.

* Only use fallback if no inferences were found

Instead of relying on the unification code to remove the fallback.
2018-11-02 09:07:32 -07:00
Andy
eabbaa415f Fix symbolCanBeReferencedAtTypeLocation for namespace that exports itself (#28295) 2018-11-01 15:10:21 -07:00
Ryan Clarke
4598943ed3 Add codefix for 'convert to unknown' diagnostic
Codefix for diagnostic error 2352: "Conversion of type '{0}' to type '{1}' may be
a mistake because neither type sufficiently overlaps with the other. If this was
intentional, convert the expression to 'unknown' first."

Add codefix for both AsExpressions and TypeAssertions
2018-11-01 06:13:25 -04:00
Nathan Shively-Sanders
0481d44501 Bad callsite inferences fall back to body usage (#28235)
For parameters, the infer-from-usage codefix uses a substantially
different codepath that previously only looked at call site uses. When
this resulted in no inferences, or bad inferences, for a single
parameter, the codefix would just use any. Only if no usages of a
function were found would the codefix use the body-inference
code.

This commit makes parameter inference fall back to body-inference code
for individual parameters when there is no inference or inference to
any.
2018-10-30 13:25:24 -07:00
Andy
437bc41e99 For path completions, include extension as a kindModifier (#28148) 2018-10-30 11:56:34 -07:00