MCPcopy Create free account
hub / github.com/microsoft/typescript-go / GetModuleSpecifier

Method GetModuleSpecifier

internal/ls/autoimport/specifiers.go:9–75  ·  view source on GitHub ↗
(
	export *Export,
	userPreferences modulespecifiers.UserPreferences,
)

Source from the content-addressed store, hash-verified

7)
8
9func (v *View) GetModuleSpecifier(
10 export *Export,
11 userPreferences modulespecifiers.UserPreferences,
12) (string, modulespecifiers.ResultKind) {
13 // Ambient module
14 if modulespecifiers.PathIsBareSpecifier(string(export.ModuleID)) {
15 specifier := string(export.ModuleID)
16 if modulespecifiers.IsExcludedByRegex(specifier, userPreferences.AutoImportSpecifierExcludeRegexes) {
17 return "", modulespecifiers.ResultKindNone
18 }
19 return string(export.ModuleID), modulespecifiers.ResultKindAmbient
20 }
21
22 if export.PackageName != "" {
23 if entrypoints, ok := v.registry.entrypoints[export.Path]; ok {
24 for _, entrypoint := range entrypoints {
25 if entrypoint.IncludeConditions.IsSubsetOf(v.conditions) && !v.conditions.Intersects(entrypoint.ExcludeConditions) {
26 specifier := modulespecifiers.ProcessEntrypointEnding(
27 entrypoint,
28 userPreferences,
29 v.program,
30 v.program.Options(),
31 v.importingFile,
32 v.getAllowedEndings(),
33 )
34
35 if !modulespecifiers.IsExcludedByRegex(specifier, userPreferences.AutoImportSpecifierExcludeRegexes) {
36 return specifier, modulespecifiers.ResultKindNodeModules
37 }
38 }
39 }
40 return "", modulespecifiers.ResultKindNone
41 }
42 }
43
44 cache := v.registry.specifierCache[v.importingFile.Path()]
45 if export.PackageName == "" {
46 if specifier, ok := cache.Load(export.Path); ok {
47 if specifier == "" {
48 return "", modulespecifiers.ResultKindNone
49 }
50 return specifier, modulespecifiers.ResultKindRelative
51 }
52 }
53
54 specifiers, kind := modulespecifiers.GetModuleSpecifiersForFileWithInfo(
55 v.importingFile,
56 export.ModuleFileName,
57 v.program.Options(),
58 v.program,
59 userPreferences,
60 modulespecifiers.ModuleSpecifierOptions{},
61 true,
62 )
63 // !!! unsure when this could return multiple specifiers combined with the
64 // new node_modules code. Possibly with local symlinks, which should be
65 // very rare.
66 for _, specifier := range specifiers {

Callers 1

GetFixesMethod · 0.95

Calls 13

getAllowedEndingsMethod · 0.95
PathIsBareSpecifierFunction · 0.92
IsExcludedByRegexFunction · 0.92
ProcessEntrypointEndingFunction · 0.92
IsSubsetOfMethod · 0.80
StoreMethod · 0.80
OptionsMethod · 0.65
PathMethod · 0.65
ContainsMethod · 0.65
stringEnum · 0.50
IntersectsMethod · 0.45

Tested by

no test coverage detected