Commit graph

45 commits

Author SHA1 Message Date
Sheetal Nandi
84a3252e76
Handle packages inside another node modules package when auto importing (#37561)
Fixes #37542
2020-03-25 16:27:02 -07:00
Sheetal Nandi
5e9c43607f
Handle auto import scenarios when using project references (#37482)
* Add test for project reference and auto import
Test for #34677

* Add project reference redirect to the possible file name to import if file is source of project reference redirect
Fixes the auto import suggestion when project is built

* Use fileExists that mimics presence of project reference redirect file when trying to get auto import file name
2020-03-19 16:53:44 -07:00
Sheetal Nandi
e60bbac84f
Fix declaration emit when the packages are included through symlinks (#37438)
* Convert symlink scenarios to virtual FS where its symlinks are correctly maintained
Adds test for #36866

* Fix the casing issue when redirects differ in casing of the file

* Make ModuleSpecifierResolutionHost internal

* Refactoring for ModuleSpecifierResolutionHost

* If any of the file path option is from node_modules folder, consider only paths in node_modules folder

* Update src/services/utilities.ts

Co-Authored-By: Andrew Branch <andrewbranch@users.noreply.github.com>

Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2020-03-17 13:21:40 -07:00
Sheetal Nandi
2458c8a016
When the imported module is through node_modules and symlink to folder that isnt node_modules (#37387)
* Add tests that fail because of symlink to non common directory node_modules

* When the imported module is through node_modules and symlink to folder that isnt node_modules
Most of the monorepo like scenarios are like this so looking at symlink to decide if file can be imported is essential
Fixes #28689
2020-03-16 11:15:39 -07:00
Sheetal Nandi
0c3019e3b3
Handle invalid package.json typings fields when generating specifiers (#36137)
Fixes #35437
2020-01-10 14:51:23 -08:00
Sheetal Nandi
f90cde4706
Fix completions when the ts installation and project are on two different windows drive (#35733)
* Fix completions when the ts installation and project are on two different windows drive
Fixes #35512

* Fix typo
2019-12-17 14:19:52 -08:00
Andrew Branch
53d2b7ed60
Don’t assume importing some JSON means you want everything imported with .js extensions (#34961) 2019-11-07 14:55:54 -08:00
Andrew Branch
454a3a0b0f
Fix auto-imports from auto type acquisition definitions (#33766)
* Fix auto-imports from ATA typings

* Compare canonical filenames in isImportablePath
2019-10-17 13:59:09 -07:00
Andrew Branch
304fcee09b
Updated: Only auto-import from package.json (#32517)
* Move package.json related utils to utilities

* Add failing test

* Make first test pass

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

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

* Make same fix in getCompletionDetails

* Fix re-exporting

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

* Remove unused method

* Remove other unused method

* Remove unused triple-slash ref

* Update comment

* Refactor findAlias to forEachAlias to reduce iterations

* Really fix re-exporting

* Use getModuleSpecifier instead of custom hack

* Fix offering auto imports to paths within node modules

* Rename things and make comments better

* Add another reexport test

* Inline `symbolHasBeenSeen`

* Simplify forEachAlias to findAlias

* Add note that symbols is mutated

* Symbol order doesn’t matter here

* Style nits

* Add test with nested package.jsons

* Fix and add tests for export * re-exports

* Don’t fail when alias isn’t found

* Make some easy optimizations

* Clean up memoization when done

* Remove unnecessary semicolon

* Make getSymbolsFromOtherSourceFileExports pure

* Cache auto imports

* Revert "Cache auto imports"

This reverts commit 8ea4829587.

* Handle merged symbols through cache

* Be safer with symbol declarations, add logging

* Improve cache invalidation for imports and exports

* Check symbol presence first

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

* Consolidate cache invalidation logic

* Fix reuseProgramStructure test

* Add more logging

* Only clear cache if symbols are different

* Refactor ambient module handling

* Start caching package.json stuff

* Support package.json searching in fourslash

* Move import suggestions cache to Project

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

* Going to backtrack some from here

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

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

* Move package.json related utils to utilities

* Add failing test

* Make first test pass

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

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

* Make same fix in getCompletionDetails

* Fix re-exporting

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

* Remove unused method

* Remove other unused method

* Remove unused triple-slash ref

* Update comment

* Refactor findAlias to forEachAlias to reduce iterations

* Really fix re-exporting

* Use getModuleSpecifier instead of custom hack

* Fix offering auto imports to paths within node modules

* Rename things and make comments better

* Add another reexport test

* Inline `symbolHasBeenSeen`

* Simplify forEachAlias to findAlias

* Add note that symbols is mutated

* Symbol order doesn’t matter here

* Style nits

* Add test with nested package.jsons

* Fix and add tests for export * re-exports

* Don’t fail when alias isn’t found

* Make some easy optimizations

* Clean up memoization when done

* Remove unnecessary semicolon

* Make getSymbolsFromOtherSourceFileExports pure

* Cache auto imports

* Revert "Cache auto imports"

This reverts commit 8ea4829587.

* Handle merged symbols through cache

* Be safer with symbol declarations, add logging

* Improve cache invalidation for imports and exports

* Check symbol presence first

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

* Consolidate cache invalidation logic

* Fix reuseProgramStructure test

* Add more logging

* Only clear cache if symbols are different

* Refactor ambient module handling

* Finish(?) sourceFileHasChangedOwnImportSuggestions

* Make package.json info model better

* Fix misplaced paren

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

* Revert unnecessary changes in moduleSpecifiers

* Revert more unnecessary changes

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

* Work around declaration emit bug

* Sync submodules?

* Delete unused type

* Add server cache tests

* Fix server fourslash editing

* Fix packageJsonInfo tests

* Add node core modules cache test and fix more fourslash

* Clean up symlink caching

* Improve logging

* Function name doesn’t make any sense anymore

* Move symlinks cache to host

* Fix markFileAsDirty from ScriptInfo

* Mark new Project members internal

* Use Path instead of fileName

* Rename AutoImportSuggestionsCache

* Improve WatchType description

* Remove entries() from packageJsonCache

* Fix path/fileName bug

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

* Let language service use Program’s symlink cache
2019-09-27 13:38:31 -07:00
Sheetal Nandi
c67c68e149 Sort the paths for module specifier by closeness to importing file path
Fixes #32970
2019-09-23 13:41:46 -07:00
Alexander T
b728bf4bfa Merge branch 'master' of https://github.com/Microsoft/TypeScript into feature/eslint 2019-08-14 13:42:02 +03:00
Ron Buckton
decc3cd671
Elide /index from auto-import when using rootDirs compiler option (#32828) 2019-08-12 16:05:15 -07:00
Alexander
ceccfd8867 array-type: [ default: array, generic: array ] 2019-08-08 21:30:18 +03:00
Alexander
481d70d50d Merge branch 'master' of https://github.com/Microsoft/TypeScript into feature/eslint 2019-08-07 21:23:10 +03:00
Ron Buckton
d75740280f
Resolve module specifier relative to moduleFile.originalFileName (#32722)
* Resolve module specifier relative to moduleFile.originalFileName

* Use baseline testing for outputs

* Added skipLibCheck to test

* Switch to using vfs.formatPatch for output
2019-08-06 13:48:58 -07:00
Alexander T
f6a50067d3 @typescript-eslint/indent 2019-06-27 11:30:03 +03:00
Wesley Wigham
bb4080c175
Collect _all_ symlinks a file may have witnessed when attempting to generate specifiers (#31571) 2019-05-23 17:17:24 -07:00
Sheetal Nandi
d53efdf380 Changes to generation of .tsbuildinfo:
- If composite or incremental then only the .tsbuildinfo will be generated
- if --out or --outFile the file is outputFile.tsbuildinfo
- if rootDir and outDir then outdir/relativePathOfConfigFromRootDir/configname.tsbuildinfo
- if just outDir then outDir/configname.tsbuild
- otherwise config.tsbuildinfo next to configFile
2019-02-28 13:46:26 -08:00
Jordi Oliveras Rovira
f41b4e088d Change usage of Array.prototype.find to ts.find. 2018-12-09 20:23:56 +01:00
Wesley Wigham
7a71887c23
Build better import paths for declaration emit/typeToString from reexports if possible (#27340)
* Build better import paths from reexports if possible, issue error on node_modules import generation

* Small refactorings

* Add file-by-file cacheing

* Minor cleanups

* Adjust error message
2018-11-13 14:07:54 -08:00
Wesley Wigham
b85e9e1cc1
Use relative module specifiers in error messages if possible (#27441)
* Use relative module specifiers in error messages if possible

* Dont share number
2018-10-08 14:36:37 -07:00
Nathan Shively-Sanders
64d0e0d448
Shorten more internal names to JS or TS (#27080) 2018-09-13 15:05:57 -07:00
Nathan Shively-Sanders
6bd1da20c9
Rename JS-specific concepts (#26795)
* Rename JS concepts

1. Assignment declaration -- an assignment that is treated like a
declaration. Previously called [JS] special (assignment|declaration),
among other things.
2. Expando -- a value that can be used as a target in assignment
declarations. Currently, a class, function or empty object literal.
Functions are allowed in Typescript, too. Previously called a JS
container, JS initializer or expando object.
3. JavaScript -> Javascript. This is annoying to type, and looks like
'Java Script' in a camelCase world.

Everything is a pure rename as far as I know. The only test change is
the API baselines, which reflect the rename from SymbolFlags.JSContainer
to SymbolFlags.Assignment.

* Remove TODO

* Rename Javascript->JS

Note that this introduces a variable name collision in a couple of
places, which I resolved like this:

```ts
const isInJavascript = isInJSFile(node);
```
2018-09-12 10:44:46 -07:00
Ron Buckton
a255d9a163 Merge branch 'master' into typesVersions 2018-09-07 13:52:12 -07:00
Andy
f78dc2ad11
importFixes: Only provide a fix using the best module specifier for a given module (#26738) 2018-08-29 16:18:56 -07:00
Andy
7b4f864b49
moduleSpecifiers: Simpler criteria for preferring relative path vs baseUrl (#25803)
* moduleSpecifiers: Simpler criteria for preferring relative path vs baseUrl

* Don't unconditonally use a path mapping
2018-08-29 15:06:26 -07:00
Ron Buckton
5f6a2cbf69 Merge branch 'master' into typesVersions 2018-08-28 17:37:23 -07:00
Andy
cff04e6050
Ensure JsonSourceFile has all the non-optional properties of SourceFile (#26162)
* Ensure JsonSourceFile has all the non-optional properties of SourceFile

* Set properties in parseSourceFile
2018-08-28 16:43:14 -07:00
Andy
b94061c587
getEditsForFileRename: Avoid changing import specifier ending (#26177)
* getEditsForFileRename: Avoid changing import specifier ending

* Support .json and .jsx extensions

* Restore typeRoots tests

* Fix json test

* When --jsx preserve is set, import ".tsx" file with ".jsx" extension

* Support ending preference in UserPreferences
2018-08-28 13:03:24 -07:00
Ron Buckton
dc5cd9676b Switch to paths-like pattern matching 2018-08-28 09:33:03 -07:00
Ron Buckton
015babb6f7 Initial support for 'typesVersions' 2018-08-20 16:57:18 -07:00
Sheetal Nandi
fea1667002 Use string contains and nodeModulesPathPart const for "/node_modules/" 2018-08-15 11:47:16 -07:00
Wesley Wigham
19e04b2cdb
Dont use baseURL relative absolute paths in declaration emit, use absolute paths in bundle emit (#26341) 2018-08-10 12:54:45 -07:00
Wesley Wigham
fce3d9f34d
Check the ambientness of a symbol name before attempting to trim it (#26312)
* Check the ambientness of a symbol name before attempting to trim it

* Use find instead of forEach, remember to also exclude global augmentations
2018-08-09 13:20:37 -07:00
Andy
9c9f3e3cf9
importFixes: When one file redirects to another, consider both for global import specifiers (#25834)
* importFixes: When one file redirects to another, consider both for global import specifiers

* Add test for #26044

* Avoid a symlinked package globally importing itself (fixes another case of #26044)

* Compare to node_modules with getCanonicalFileName
2018-07-31 17:28:56 -07:00
Wesley Wigham
59854bbd55
Inspect all possible module paths when looking for the best one to create a specifier with (#25850)
* Inspect all possible specifier paths when looking for the best one

* Add missing secondary option from test
2018-07-24 13:56:21 -07:00
Andy
30c41492d9
moduleSpecifiers: Allow "*" as a path mapping (#25881) 2018-07-23 17:11:30 -07:00
Andy
304d45d833
Canonicalize path before calling startsWith (#25364)
* Canonicalize path before calling `startsWith`

* More specific type for sourceDirectory, and add fourslash test

* Update API (#24966)
2018-07-03 11:23:19 -07:00
Andy
7dc66e916a
moduleSpecifiers: specifier from "rootDirs" should be treated as relative (#25369) 2018-07-02 11:14:49 -07:00
Wesley Wigham
30db30055f
Fix module specifier case handling for declaration emit (#25110) 2018-06-29 11:02:43 -07:00
Andy
ab9e913af3
getEditsForFileRename: Test both before and after the rename (#25074) 2018-06-26 16:55:51 -07:00
Wesley Wigham
a77068827d
Handle combinations of rootdir and outdir when calculating paths (#24941) 2018-06-14 11:07:46 -07:00
Wesley Wigham
61fb222cd2
Use symlinks when looking for module names for declaration emit (#24874)
* fix symlink tag, support arbitrary (ie, directory) links via @link

Introduce indirect symlink lookup to specifier deriver

Use fileset, move exec

vfs path resolution :shakes fist:

Apply files symlink relative to dirname

Use directory function

* Accept really bad baseline updates
2018-06-12 12:52:44 -07:00
Andy
3822e3e4ed
tryGetModuleNameAsNodeModule: Ignore file extension (#24774) 2018-06-07 15:45:03 -07:00
Wesley Wigham
d9b93903c0
Use more nodelike paths for import types when possible (#24610)
* Use more nodelike paths for import types when possible

* move functionality from services into compiler, fix with propert file/directory conflict handling

* mark suspect cast
2018-06-05 12:54:36 -07:00
Renamed from src/services/codefixes/moduleSpecifiers.ts (Browse further)