Skip to content

Commit

Permalink
fix: remove block_on and make all futures Send
Browse files Browse the repository at this point in the history
Due to a compiler bug, non-Send locals live longer than they should
after return statements and they cannot be dropped either. Since the
liveness checker only depends on the scope, the solution is to hoist
the returning branches to outside of the loop, resulting in ugly code.
  • Loading branch information
Desdaemon committed Sep 12, 2023
1 parent f3a4c60 commit 118664d
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 144 deletions.
2 changes: 1 addition & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function downloadLspBinary(context: ExtensionContext) {
const preferNightly = !!workspace.getConfiguration("odoo-lsp.binary").get("preferNightly");
const overrideVersion = workspace.getConfiguration("odoo-lsp.binary").get("overrideVersion");

let release = overrideVersion || 'nightly';
let release = overrideVersion || "nightly";
if (!preferNightly && !overrideVersion) {
release = context.extension.packageJSON._release || release;
}
Expand Down
18 changes: 11 additions & 7 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::sync::atomic::Ordering::Relaxed;
use std::sync::atomic::{AtomicBool, AtomicUsize};

use dashmap::{DashMap, DashSet};
use futures::executor::block_on;
use globwalk::FileType;
use lasso::{Key, Spur};
use log::debug;
Expand All @@ -19,7 +18,7 @@ use odoo_lsp::config::{Config, ModuleConfig, ReferencesConfig, SymbolsConfig};
use odoo_lsp::index::{interner, Index, Interner, ModuleName, RecordId, SymbolSet};
use odoo_lsp::model::{Field, FieldKind, ModelEntry, ModelLocation, ModelName};
use odoo_lsp::record::Record;
use odoo_lsp::utils::isolate::Isolate;
// use odoo_lsp::utils::isolate::Isolate;
use odoo_lsp::{some, utils::*};

pub struct Backend {
Expand All @@ -33,7 +32,7 @@ pub struct Backend {
pub root_setup: AtomicBool,
pub symbols_limit: AtomicUsize,
pub references_limit: AtomicUsize,
pub isolate: Isolate,
// pub isolate: Isolate,
}

#[derive(Debug, Default)]
Expand Down Expand Up @@ -325,19 +324,24 @@ impl Backend {
}),
}))
}
pub fn jump_def_field_name(&self, field: &str, model: &str) -> miette::Result<Option<Location>> {
pub async fn jump_def_field_name(&self, field: &str, model: &str) -> miette::Result<Option<Location>> {
let model = interner().get_or_intern(model);
let mut entry = some!(self.index.models.get_mut(&model.into()));
let field = some!(interner().get(field));
let fields = block_on(self.populate_field_names(&mut entry, &[]))?;
let fields = self.populate_field_names(&mut entry, &[]).await?;
let field = some!(fields.get(&field.into()));
Ok(Some(field.location.clone().into()))
}
pub fn hover_field_name(&self, name: &str, model: &str, range: Option<Range>) -> miette::Result<Option<Hover>> {
pub async fn hover_field_name(
&self,
name: &str,
model: &str,
range: Option<Range>,
) -> miette::Result<Option<Hover>> {
let model = interner().get_or_intern(model);
let mut entry = some!(self.index.models.get_mut(&model.into()));
let field = some!(interner().get(name));
let fields = block_on(self.populate_field_names(&mut entry, &[]))?;
let fields = self.populate_field_names(&mut entry, &[]).await?;
let field = some!(fields.get(&field.into()));
Ok(Some(Hover {
range,
Expand Down
25 changes: 9 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tower_lsp::{LanguageServer, LspService, Server};
use odoo_lsp::config::Config;
use odoo_lsp::index::{interner, Interner};
use odoo_lsp::model::FieldKind;
use odoo_lsp::utils::isolate::Isolate;
// use odoo_lsp::utils::isolate::Isolate;
use odoo_lsp::{format_loc, some, utils::*};

mod analyze;
Expand Down Expand Up @@ -126,7 +126,7 @@ impl LanguageServer for Backend {
root_setup: _,
symbols_limit: _,
references_limit: _,
isolate: _,
// isolate: _,
} = self;
document_map.remove(path);
record_ranges.remove(path);
Expand Down Expand Up @@ -401,10 +401,8 @@ impl LanguageServer for Backend {
return Ok(None);
};
if ext == "xml" {
let completions = self.isolate.send_task(|send| {
Box::pin(async { _ = send.send(self.xml_completions(params, document.value().clone()).await) })
});
match completions.await.expect("isolate error") {
let completions = self.xml_completions(params, document.value().clone()).await;
match completions {
Ok(ret) => Ok(ret),
Err(report) => {
self.client
Expand All @@ -418,15 +416,10 @@ impl LanguageServer for Backend {
debug!("Bug: did not build AST for {}", uri.path());
return Ok(None);
};
let completions = self.isolate.send_task(|send| {
Box::pin(async {
_ = send.send(
self.python_completions(params, ast.value().clone(), document.value().clone())
.await,
);
})
});
match completions.await.expect("isolate error") {
let completions = self
.python_completions(params, ast.value().clone(), document.value().clone())
.await;
match completions {
Ok(ret) => Ok(ret),
Err(err) => {
self.client
Expand Down Expand Up @@ -622,7 +615,7 @@ async fn main() {
ast_map: DashMap::new(),
symbols_limit: AtomicUsize::new(100),
references_limit: AtomicUsize::new(100),
isolate: Isolate::new(),
// isolate: Isolate::new(),
})
.finish();

Expand Down
Loading

0 comments on commit 118664d

Please sign in to comment.