Skip to content

Commit 142a3af

Browse files
committed
code_action
1 parent 8d637fb commit 142a3af

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

cli/lsp/language_server.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,7 @@ impl Inner {
16071607
async fn code_action(
16081608
&self,
16091609
params: CodeActionParams,
1610+
token: CancellationToken,
16101611
) -> LspResult<Option<CodeActionResponse>> {
16111612
let specifier = self
16121613
.url_map
@@ -1688,6 +1689,7 @@ impl Inner {
16881689
&specifier,
16891690
),
16901691
asset_or_doc.scope().cloned(),
1692+
token.clone(),
16911693
)
16921694
.await;
16931695
for action in actions {
@@ -1794,6 +1796,7 @@ impl Inner {
17941796
params.context.trigger_kind,
17951797
only,
17961798
asset_or_doc.scope().cloned(),
1799+
token,
17971800
)
17981801
.await?;
17991802
let mut refactor_actions = Vec::<CodeAction>::new();
@@ -3372,7 +3375,12 @@ impl tower_lsp::LanguageServer for LanguageServer {
33723375
if !self.init_flag.is_raised() {
33733376
self.init_flag.wait_raised().await;
33743377
}
3375-
self.inner.read().await.code_action(params).await
3378+
let ls = self.clone();
3379+
self
3380+
.spawn_with_cancellation(move |token| async move {
3381+
ls.inner.read().await.code_action(params, token).await
3382+
})
3383+
.await
33763384
}
33773385

33783386
async fn code_action_resolve(

cli/lsp/tsc.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ impl TsServer {
654654
format_code_settings: FormatCodeSettings,
655655
preferences: UserPreferences,
656656
scope: Option<ModuleSpecifier>,
657+
token: CancellationToken,
657658
) -> Vec<CodeFixAction> {
658659
let req = TscRequest::GetCodeFixesAtPosition(Box::new((
659660
self.specifier_map.denormalize(&specifier),
@@ -664,7 +665,9 @@ impl TsServer {
664665
preferences,
665666
)));
666667
let result = self
667-
.request::<Vec<CodeFixAction>>(snapshot, req, scope)
668+
.request_with_cancellation::<Vec<CodeFixAction>>(
669+
snapshot, req, scope, token,
670+
)
668671
.await
669672
.and_then(|mut actions| {
670673
for action in &mut actions {
@@ -695,6 +698,7 @@ impl TsServer {
695698
trigger_kind: Option<lsp::CodeActionTriggerKind>,
696699
only: String,
697700
scope: Option<ModuleSpecifier>,
701+
token: CancellationToken,
698702
) -> Result<Vec<ApplicableRefactorInfo>, LspError> {
699703
let trigger_kind = trigger_kind.map(|reason| match reason {
700704
lsp::CodeActionTriggerKind::INVOKED => "invoked",
@@ -708,10 +712,13 @@ impl TsServer {
708712
trigger_kind,
709713
only,
710714
)));
711-
self.request(snapshot, req, scope).await.map_err(|err| {
712-
log::error!("Failed to request to tsserver {}", err);
713-
LspError::invalid_request()
714-
})
715+
self
716+
.request_with_cancellation(snapshot, req, scope, token)
717+
.await
718+
.map_err(|err| {
719+
log::error!("Failed to request to tsserver {}", err);
720+
LspError::invalid_request()
721+
})
715722
}
716723

717724
pub async fn get_combined_code_fix(

0 commit comments

Comments
 (0)