Skip to content
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

Merged
merged 2 commits into from
Jan 18, 2022
Merged

Conversation

floitsch
Copy link
Member

No description provided.

@floitsch floitsch requested a review from jstroem January 17, 2022 18:03
@cla-bot cla-bot bot added the cla-signed The contributors have signed the CLA label Jan 17, 2022
}
}

func (cp *CompilerFSProtocol) HandleConn(conn io.ReadWriter) {
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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.

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()
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

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.

@floitsch floitsch merged commit 9636712 into master Jan 18, 2022
@floitsch floitsch deleted the compiler_lsp_go.10.refactor_go branch January 18, 2022 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The contributors have signed the CLA
Development

Successfully merging this pull request may close these issues.

2 participants