forked from hashicorp/terraform-ls
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
langserver: Refactor logic for easier testing
Separate package for high-level errors and server controller makes it easier to test the server and help avoid import cycles.
- Loading branch information
1 parent
ec1a374
commit 7a183d2
Showing
9 changed files
with
183 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package errors | ||
|
||
import ( | ||
"github.com/creachadair/jrpc2/code" | ||
) | ||
|
||
const ServerNotInitialized code.Code = -32002 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package srvctl | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/creachadair/jrpc2/code" | ||
"github.com/hashicorp/terraform-ls/langserver/errors" | ||
) | ||
|
||
type unexpectedSrvState struct { | ||
ExpectedState serverState | ||
CurrentState serverState | ||
} | ||
|
||
func (e *unexpectedSrvState) Error() string { | ||
return fmt.Sprintf("server is not %s, current state: %s", | ||
e.ExpectedState, e.CurrentState) | ||
} | ||
|
||
func srvNotInitializedErr(state serverState) error { | ||
uss := &unexpectedSrvState{ | ||
ExpectedState: stateInitializedConfirmed, | ||
CurrentState: state, | ||
} | ||
if state < stateInitializedConfirmed { | ||
return fmt.Errorf("%w: %s", errors.ServerNotInitialized.Err(), uss) | ||
} | ||
if state == stateDown { | ||
return fmt.Errorf("%w: %s", code.InvalidRequest.Err(), uss) | ||
} | ||
|
||
return uss | ||
} | ||
|
||
func srvAlreadyInitializedErr(reqID string) error { | ||
return fmt.Errorf("%w: Server was already initialized via request ID %s", | ||
code.SystemError.Err(), reqID) | ||
} | ||
|
||
func srvAlreadyDownErr(reqID string) error { | ||
return fmt.Errorf("%w: server was already shut down via request %s", | ||
code.InvalidRequest.Err(), reqID) | ||
} |
Oops, something went wrong.