-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor file server in Toit LSP. #315
Conversation
} | ||
} | ||
|
||
func (cp *CompilerFSProtocol) HandleConn(conn io.ReadWriter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code here has just been moved from file_server.go
The only lines changed are at the very top (scanner
and w
)
Content []byte | ||
} | ||
|
||
type CompilerFSProtocol struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these fields were previously part of the FileServer.
"go.uber.org/zap" | ||
) | ||
|
||
type FileSystem interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moved from file_server.go.
PackageCachePaths() ([]string, error) | ||
} | ||
|
||
type File struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moved from file_server.go.
return | ||
} | ||
|
||
func (cp *CompilerFSProtocol) ServedPackageCachePaths() []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these functions were part of the FileServer.
} | ||
|
||
type File struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All removed entries here were moved to the protocol.
Read(path string) (File, error) | ||
ListDirectory(path string) ([]string, error) | ||
PackageCachePaths() ([]string, error) | ||
type FileServer interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New interface.
Currently there is only one class implementing it (PortFileServer
) but I will add a new one soon.
tools/toitlsp/cmd/repro.go
Outdated
fileServer := compiler.NewFileServer(fs, logger, reproFS.sdkPath) | ||
go fileServer.ListenAndServe(fmt.Sprintf(":%d", port)) | ||
fileServer := compiler.NewPortFileServer(fs, logger, reproFS.sdkPath, fmt.Sprintf(":%d", port)) | ||
go fileServer.Start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer ListenAndServe
because it mimics the http server API in go, but if you really want to rename this to Run
.
NormallyStart
is non-blocking whereasRun
is blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that will make it relatable to os/exec.Cmd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Thanks.
The reason I'm changing it to Run
is because I'm adding another server that only uses a pipe.
No description provided.