Skip to content

Commit 09e7953

Browse files
authored
Clean up host related code (#1354)
1 parent b7f1b49 commit 09e7953

File tree

21 files changed

+47
-129
lines changed

21 files changed

+47
-129
lines changed

cmd/tsgo/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func runAPI(args []string) int {
2626
Out: os.Stdout,
2727
Err: os.Stderr,
2828
Cwd: *cwd,
29-
NewLine: "\n",
3029
DefaultLibraryPath: defaultLibraryPath,
3130
})
3231

cmd/tsgo/sys.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"fmt"
55
"io"
66
"os"
7-
"runtime"
87
"time"
98

109
"github.com/microsoft/typescript-go/internal/bundled"
11-
"github.com/microsoft/typescript-go/internal/core"
1210
"github.com/microsoft/typescript-go/internal/execute"
1311
"github.com/microsoft/typescript-go/internal/tspath"
1412
"github.com/microsoft/typescript-go/internal/vfs"
@@ -19,7 +17,6 @@ type osSys struct {
1917
writer io.Writer
2018
fs vfs.FS
2119
defaultLibraryPath string
22-
newLine string
2320
cwd string
2421
start time.Time
2522
}
@@ -44,10 +41,6 @@ func (s *osSys) GetCurrentDirectory() string {
4441
return s.cwd
4542
}
4643

47-
func (s *osSys) NewLine() string {
48-
return s.newLine
49-
}
50-
5144
func (s *osSys) Writer() io.Writer {
5245
return s.writer
5346
}
@@ -69,7 +62,6 @@ func newSystem() *osSys {
6962
fs: bundled.WrapFS(osvfs.FS()),
7063
defaultLibraryPath: bundled.LibPath(),
7164
writer: os.Stdout,
72-
newLine: core.IfElse(runtime.GOOS == "windows", "\r\n", "\n"),
7365
start: time.Now(),
7466
}
7567
}

internal/api/api.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ func (api *API) Trace(s string) {
111111
api.options.Logger.Info(s)
112112
}
113113

114-
// NewLine implements ProjectHost.
115-
func (api *API) NewLine() string {
116-
return api.host.NewLine()
117-
}
118-
119114
// PositionEncoding implements ProjectHost.
120115
func (api *API) PositionEncoding() lsproto.PositionEncodingKind {
121116
return lsproto.PositionEncodingKindUTF8

internal/api/host.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ type APIHost interface {
66
FS() vfs.FS
77
DefaultLibraryPath() string
88
GetCurrentDirectory() string
9-
NewLine() string
109
}

internal/api/server.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type ServerOptions struct {
6161
Out io.Writer
6262
Err io.Writer
6363
Cwd string
64-
NewLine string
6564
DefaultLibraryPath string
6665
}
6766

@@ -98,7 +97,6 @@ func NewServer(options *ServerOptions) *Server {
9897
w: bufio.NewWriter(options.Out),
9998
stderr: options.Err,
10099
cwd: options.Cwd,
101-
newLine: options.NewLine,
102100
fs: bundled.WrapFS(osvfs.FS()),
103101
defaultLibraryPath: options.DefaultLibraryPath,
104102
}
@@ -126,11 +124,6 @@ func (s *Server) GetCurrentDirectory() string {
126124
return s.cwd
127125
}
128126

129-
// NewLine implements APIHost.
130-
func (s *Server) NewLine() string {
131-
return s.newLine
132-
}
133-
134127
func (s *Server) Run() error {
135128
for {
136129
messageType, method, payload, err := s.readRequest("")

internal/checker/checker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ foo.bar;`
3636
fs = bundled.WrapFS(fs)
3737

3838
cd := "/"
39-
host := compiler.NewCompilerHost(nil, cd, fs, bundled.LibPath(), nil)
39+
host := compiler.NewCompilerHost(cd, fs, bundled.LibPath())
4040

4141
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, host, nil)
4242
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
@@ -70,7 +70,7 @@ func TestCheckSrcCompiler(t *testing.T) {
7070

7171
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")
7272

73-
host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil)
73+
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath())
7474
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
7575
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
7676
p := compiler.NewProgram(compiler.ProgramOptions{
@@ -87,7 +87,7 @@ func BenchmarkNewChecker(b *testing.B) {
8787

8888
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")
8989

90-
host := compiler.NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil)
90+
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath())
9191
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
9292
assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line")
9393
p := compiler.NewProgram(compiler.ProgramOptions{

internal/compiler/host.go

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package compiler
22

33
import (
44
"github.com/microsoft/typescript-go/internal/ast"
5-
"github.com/microsoft/typescript-go/internal/collections"
65
"github.com/microsoft/typescript-go/internal/core"
76
"github.com/microsoft/typescript-go/internal/parser"
87
"github.com/microsoft/typescript-go/internal/tsoptions"
@@ -15,50 +14,36 @@ type CompilerHost interface {
1514
FS() vfs.FS
1615
DefaultLibraryPath() string
1716
GetCurrentDirectory() string
18-
NewLine() string
1917
Trace(msg string)
2018
GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile
2119
GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine
2220
}
2321

24-
type FileInfo struct {
25-
Name string
26-
Size int64
27-
}
28-
2922
var _ CompilerHost = (*compilerHost)(nil)
3023

3124
type compilerHost struct {
32-
options *core.CompilerOptions
33-
currentDirectory string
34-
fs vfs.FS
35-
defaultLibraryPath string
36-
extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry]
25+
currentDirectory string
26+
fs vfs.FS
27+
defaultLibraryPath string
3728
}
3829

3930
func NewCachedFSCompilerHost(
40-
options *core.CompilerOptions,
4131
currentDirectory string,
4232
fs vfs.FS,
4333
defaultLibraryPath string,
44-
extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry],
4534
) CompilerHost {
46-
return NewCompilerHost(options, currentDirectory, cachedvfs.From(fs), defaultLibraryPath, extendedConfigCache)
35+
return NewCompilerHost(currentDirectory, cachedvfs.From(fs), defaultLibraryPath)
4736
}
4837

4938
func NewCompilerHost(
50-
options *core.CompilerOptions,
5139
currentDirectory string,
5240
fs vfs.FS,
5341
defaultLibraryPath string,
54-
extendedConfigCache *collections.SyncMap[tspath.Path, *tsoptions.ExtendedConfigCacheEntry],
5542
) CompilerHost {
5643
return &compilerHost{
57-
options: options,
58-
currentDirectory: currentDirectory,
59-
fs: fs,
60-
defaultLibraryPath: defaultLibraryPath,
61-
extendedConfigCache: extendedConfigCache,
44+
currentDirectory: currentDirectory,
45+
fs: fs,
46+
defaultLibraryPath: defaultLibraryPath,
6247
}
6348
}
6449

@@ -70,21 +55,10 @@ func (h *compilerHost) DefaultLibraryPath() string {
7055
return h.defaultLibraryPath
7156
}
7257

73-
func (h *compilerHost) SetOptions(options *core.CompilerOptions) {
74-
h.options = options
75-
}
76-
7758
func (h *compilerHost) GetCurrentDirectory() string {
7859
return h.currentDirectory
7960
}
8061

81-
func (h *compilerHost) NewLine() string {
82-
if h.options == nil {
83-
return "\n"
84-
}
85-
return h.options.NewLine.GetNewLineCharacter()
86-
}
87-
8862
func (h *compilerHost) Trace(msg string) {
8963
//!!! TODO: implement
9064
}

internal/compiler/program_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestProgram(t *testing.T) {
240240
CompilerOptions: &opts,
241241
},
242242
},
243-
Host: NewCompilerHost(&opts, "c:/dev/src", fs, bundled.LibPath(), nil),
243+
Host: NewCompilerHost("c:/dev/src", fs, bundled.LibPath()),
244244
})
245245

246246
actualFiles := []string{}
@@ -277,7 +277,7 @@ func BenchmarkNewProgram(b *testing.B) {
277277
CompilerOptions: &opts,
278278
},
279279
},
280-
Host: NewCompilerHost(&opts, "c:/dev/src", fs, bundled.LibPath(), nil),
280+
Host: NewCompilerHost("c:/dev/src", fs, bundled.LibPath()),
281281
}
282282

283283
for b.Loop() {
@@ -294,7 +294,7 @@ func BenchmarkNewProgram(b *testing.B) {
294294
fs := osvfs.FS()
295295
fs = bundled.WrapFS(fs)
296296

297-
host := NewCompilerHost(nil, rootPath, fs, bundled.LibPath(), nil)
297+
host := NewCompilerHost(rootPath, fs, bundled.LibPath())
298298

299299
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), nil, host, nil)
300300
assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line")

internal/execute/outputs.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func reportStatistics(sys System, program *compiler.Program, result compileAndEm
9898
}
9999

100100
func printVersion(sys System) {
101-
fmt.Fprint(sys.Writer(), diagnostics.Version_0.Format(core.Version())+sys.NewLine())
101+
fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Format(core.Version()))
102102
sys.EndWrite()
103103
}
104104

@@ -144,7 +144,7 @@ func getHeader(sys System, message string) []string {
144144
// header.push("".padStart(leftAlign) + tsIconSecondLine + sys.newLine);
145145
// }
146146
// else {
147-
header = append(header, message+sys.NewLine(), sys.NewLine())
147+
header = append(header, message+"\n", "\n")
148148
// }
149149
return header
150150
}
@@ -156,15 +156,15 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) {
156156
for _, example := range examples {
157157
// !!! colors
158158
// output.push(" " + colors.blue(example) + sys.newLine);
159-
output = append(output, " ", example, sys.NewLine())
159+
output = append(output, " ", example, "\n")
160160
}
161-
output = append(output, " ", desc.Format(), sys.NewLine(), sys.NewLine())
161+
output = append(output, " ", desc.Format(), "\n", "\n")
162162
}
163163

164164
msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Format() + " - " + diagnostics.Version_0.Format(core.Version())
165165
output = append(output, getHeader(sys, msg)...)
166166

167-
output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, sys.NewLine(), sys.NewLine())
167+
output = append(output /*colors.bold(*/, diagnostics.COMMON_COMMANDS.Format() /*)*/, "\n", "\n")
168168

169169
example([]string{"tsc"}, diagnostics.Compiles_the_current_project_tsconfig_json_in_the_working_directory)
170170
example([]string{"tsc app.ts util.ts"}, diagnostics.Ignoring_tsconfig_json_compiles_the_specified_files_with_default_compiler_options)
@@ -206,15 +206,15 @@ func generateSectionOptionsOutput(
206206
afterOptionsDescription *string,
207207
) (output []string) {
208208
// !!! color
209-
output = append(output /*createColors(sys).bold(*/, sectionName /*)*/, sys.NewLine(), sys.NewLine())
209+
output = append(output /*createColors(sys).bold(*/, sectionName /*)*/, "\n", "\n")
210210

211211
if beforeOptionsDescription != nil {
212-
output = append(output, *beforeOptionsDescription, sys.NewLine(), sys.NewLine())
212+
output = append(output, *beforeOptionsDescription, "\n", "\n")
213213
}
214214
if !subCategory {
215215
output = append(output, generateGroupOptionOutput(sys, options)...)
216216
if afterOptionsDescription != nil {
217-
output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine())
217+
output = append(output, *afterOptionsDescription, "\n", "\n")
218218
}
219219
return output
220220
}
@@ -227,11 +227,11 @@ func generateSectionOptionsOutput(
227227
categoryMap[curCategory] = append(categoryMap[curCategory], option)
228228
}
229229
for key, value := range categoryMap {
230-
output = append(output, "### ", key, sys.NewLine(), sys.NewLine())
230+
output = append(output, "### ", key, "\n", "\n")
231231
output = append(output, generateGroupOptionOutput(sys, value)...)
232232
}
233233
if afterOptionsDescription != nil {
234-
output = append(output, *afterOptionsDescription, sys.NewLine(), sys.NewLine())
234+
output = append(output, *afterOptionsDescription, "\n", "\n")
235235
}
236236

237237
return output
@@ -258,8 +258,8 @@ func generateGroupOptionOutput(sys System, optionsList []*tsoptions.CommandLineO
258258
}
259259

260260
// make sure always a blank line in the end.
261-
if len(lines) < 2 || lines[len(lines)-2] != sys.NewLine() {
262-
lines = append(lines, sys.NewLine())
261+
if len(lines) < 2 || lines[len(lines)-2] != "\n" {
262+
lines = append(lines, "\n")
263263
}
264264

265265
return lines
@@ -312,25 +312,25 @@ func generateOptionOutput(
312312
// !!! }
313313
// !!! text.push(sys.newLine);
314314
} else {
315-
text = append(text /* !!! colors.blue(name) */, name, sys.NewLine())
315+
text = append(text /* !!! colors.blue(name) */, name, "\n")
316316
if option.Description != nil {
317317
text = append(text, option.Description.Format())
318318
}
319-
text = append(text, sys.NewLine())
319+
text = append(text, "\n")
320320
if showAdditionalInfoOutput(valueCandidates, option) {
321321
if valueCandidates != nil {
322322
text = append(text, valueCandidates.valueType, " ", valueCandidates.possibleValues)
323323
}
324324
if defaultValueDescription != "" {
325325
if valueCandidates != nil {
326-
text = append(text, sys.NewLine())
326+
text = append(text, "\n")
327327
}
328328
text = append(text, diagnostics.X_default_Colon.Format(), " ", defaultValueDescription)
329329
}
330330

331-
text = append(text, sys.NewLine())
331+
text = append(text, "\n")
332332
}
333-
text = append(text, sys.NewLine())
333+
text = append(text, "\n")
334334
}
335335

336336
return text

internal/execute/system.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type System interface {
1313
FS() vfs.FS
1414
DefaultLibraryPath() string
1515
GetCurrentDirectory() string
16-
NewLine() string // #241 eventually we want to use "\n"
1716

1817
Now() time.Time
1918
SinceStart() time.Duration

0 commit comments

Comments
 (0)