-
Notifications
You must be signed in to change notification settings - Fork 582
/
Copy pathlanguageservice.go
67 lines (54 loc) · 1.77 KB
/
languageservice.go
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
package ls
import (
"fmt"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/compiler"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/tspath"
"github.com/microsoft/typescript-go/internal/vfs"
)
var _ compiler.CompilerHost = (*LanguageService)(nil)
type LanguageService struct {
host Host
}
func NewLanguageService(host Host) *LanguageService {
return &LanguageService{
host: host,
}
}
// FS implements compiler.CompilerHost.
func (l *LanguageService) FS() vfs.FS {
return l.host.FS()
}
// DefaultLibraryPath implements compiler.CompilerHost.
func (l *LanguageService) DefaultLibraryPath() string {
return l.host.DefaultLibraryPath()
}
// GetCurrentDirectory implements compiler.CompilerHost.
func (l *LanguageService) GetCurrentDirectory() string {
return l.host.GetCurrentDirectory()
}
// NewLine implements compiler.CompilerHost.
func (l *LanguageService) NewLine() string {
return l.host.NewLine()
}
// Trace implements compiler.CompilerHost.
func (l *LanguageService) Trace(msg string) {
l.host.Trace(msg)
}
// GetSourceFile implements compiler.CompilerHost.
func (l *LanguageService) GetSourceFile(fileName string, path tspath.Path, languageVersion core.ScriptTarget) *ast.SourceFile {
return l.host.GetSourceFile(fileName, path, languageVersion)
}
// GetProgram updates the program if the project version has changed.
func (l *LanguageService) GetProgram() *compiler.Program {
return l.host.GetProgram()
}
func (l *LanguageService) getProgramAndFile(fileName string) (*compiler.Program, *ast.SourceFile, error) {
program := l.GetProgram()
file := program.GetSourceFile(fileName)
if file == nil {
return nil, nil, fmt.Errorf("file not found")
}
return program, file, nil
}