-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract
RubyLsp::TestHelper
for addons to use (#1833)
Extract RubyLsp::TestHelper for addons to use Co-authored-by: Andy Waite <andyw8@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
44 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
# NOTE: This module is intended to be used by addons for writing their own tests, so keep that in mind if changing. | ||
|
||
module RubyLsp | ||
module TestHelper | ||
extend T::Sig | ||
|
||
sig do | ||
type_parameters(:T) | ||
.params( | ||
source: T.nilable(String), | ||
uri: URI::Generic, | ||
block: T.proc.params(server: RubyLsp::Server, uri: URI::Generic).returns(T.type_parameter(:T)), | ||
).returns(T.type_parameter(:T)) | ||
end | ||
def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), &block) | ||
server = RubyLsp::Server.new(test_mode: true) | ||
server.process_message(method: "initialized") | ||
|
||
if source | ||
server.process_message({ | ||
method: "textDocument/didOpen", | ||
params: { | ||
textDocument: { | ||
uri: uri, | ||
text: source, | ||
version: 1, | ||
}, | ||
}, | ||
}) | ||
end | ||
|
||
index = server.index | ||
index.index_single(RubyIndexer::IndexablePath.new(nil, T.must(uri.to_standardized_path)), source) | ||
block.call(server, uri) | ||
ensure | ||
T.must(server).run_shutdown | ||
end | ||
end | ||
end |
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