-
Notifications
You must be signed in to change notification settings - Fork 965
Expand file tree
/
Copy pathhost.go
More file actions
98 lines (85 loc) · 2.67 KB
/
host.go
File metadata and controls
98 lines (85 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package compiler
import (
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/locale"
"github.com/microsoft/typescript-go/internal/parser"
"github.com/microsoft/typescript-go/internal/tsoptions"
"github.com/microsoft/typescript-go/internal/tspath"
"github.com/microsoft/typescript-go/internal/vfs"
"github.com/microsoft/typescript-go/internal/vfs/cachedvfs"
)
type CompilerHost interface {
FS() vfs.FS
DefaultLibraryPath() string
GetCurrentDirectory() string
Locale() locale.Locale
Trace(msg string)
GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile
GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine
}
var _ CompilerHost = (*compilerHost)(nil)
type compilerHost struct {
currentDirectory string
fs vfs.FS
locale locale.Locale
defaultLibraryPath string
extendedConfigCache tsoptions.ExtendedConfigCache
trace func(msg string)
}
func NewCachedFSCompilerHost(
currentDirectory string,
fs vfs.FS,
locale locale.Locale,
defaultLibraryPath string,
extendedConfigCache tsoptions.ExtendedConfigCache,
trace func(msg string),
) CompilerHost {
return NewCompilerHost(currentDirectory, cachedvfs.From(fs), locale, defaultLibraryPath, extendedConfigCache, trace)
}
func NewCompilerHost(
currentDirectory string,
fs vfs.FS,
locale locale.Locale,
defaultLibraryPath string,
extendedConfigCache tsoptions.ExtendedConfigCache,
trace func(msg string),
) CompilerHost {
if trace == nil {
trace = func(msg string) {}
}
return &compilerHost{
currentDirectory: currentDirectory,
fs: fs,
locale: locale,
defaultLibraryPath: defaultLibraryPath,
extendedConfigCache: extendedConfigCache,
trace: trace,
}
}
func (h *compilerHost) FS() vfs.FS {
return h.fs
}
func (h *compilerHost) DefaultLibraryPath() string {
return h.defaultLibraryPath
}
func (h *compilerHost) GetCurrentDirectory() string {
return h.currentDirectory
}
func (h *compilerHost) Locale() locale.Locale {
return h.locale
}
func (h *compilerHost) Trace(msg string) {
h.trace(msg)
}
func (h *compilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile {
text, ok := h.FS().ReadFile(opts.FileName)
if !ok {
return nil
}
return parser.ParseSourceFile(opts, text, core.GetScriptKindFromFileName(opts.FileName))
}
func (h *compilerHost) GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine {
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, nil, h, h.extendedConfigCache)
return commandLine
}