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

Function fmtMain

internal/execute/tsc.go:65–88  ·  view source on GitHub ↗
(sys tsc.System, input, output string)

Source from the content-addressed store, hash-verified

63}
64
65func fmtMain(sys tsc.System, input, output string) tsc.ExitStatus {
66 ctx := format.WithFormatCodeSettings(context.Background(), lsutil.GetDefaultFormatCodeSettings(), "\n")
67 input = string(tspath.ToPath(input, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames()))
68 output = string(tspath.ToPath(output, sys.GetCurrentDirectory(), sys.FS().UseCaseSensitiveFileNames()))
69 fileContent, ok := sys.FS().ReadFile(input)
70 if !ok {
71 fmt.Fprintln(sys.Writer(), "File not found:", input)
72 return tsc.ExitStatusNotImplemented
73 }
74 text := fileContent
75 pathified := tspath.ToPath(input, sys.GetCurrentDirectory(), true)
76 sourceFile := parser.ParseSourceFile(ast.SourceFileParseOptions{
77 FileName: string(pathified),
78 Path: pathified,
79 }, text, core.GetScriptKindFromFileName(string(pathified)))
80 edits := format.FormatDocument(ctx, sourceFile)
81 newText := core.ApplyBulkEdits(text, edits)
82
83 if err := sys.FS().WriteFile(output, newText); err != nil {
84 fmt.Fprintln(sys.Writer(), err.Error())
85 return tsc.ExitStatusNotImplemented
86 }
87 return tsc.ExitStatusSuccess
88}
89
90func tscBuildCompilation(ctx context.Context, sys tsc.System, buildCommand *tsoptions.ParsedBuildCommandLine, testing tsc.CommandLineTesting) tsc.CommandLineResult {
91 locale := buildCommand.Locale()

Callers

nothing calls this directly

Calls 15

WithFormatCodeSettingsFunction · 0.92
ToPathFunction · 0.92
ParseSourceFileFunction · 0.92
FormatDocumentFunction · 0.92
ApplyBulkEditsFunction · 0.92
GetCurrentDirectoryMethod · 0.65
FSMethod · 0.65
ReadFileMethod · 0.65
WriterMethod · 0.65

Tested by

no test coverage detected