Skip to content

Commit

Permalink
Cleanup old syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Oct 23, 2023
1 parent d52e0cf commit 3faf115
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
2 changes: 0 additions & 2 deletions compiler/crates/relay-lsp/src/completion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,6 @@ pub fn on_completion(
state: &impl GlobalState,
params: <Completion as Request>::Params,
) -> LSPRuntimeResult<<Completion as Request>::Result> {
state.ensure_documents_are_synced();

match state.extract_executable_document_from_text(&params.text_document_position, 0) {
Ok((document, position_span)) => {
let project_name = state
Expand Down
48 changes: 4 additions & 44 deletions compiler/crates/relay-lsp/src/server/lsp_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Condvar;
use std::sync::Mutex;

use common::PerfLogger;
use common::SourceLocationKey;
Expand Down Expand Up @@ -138,8 +136,6 @@ pub trait GlobalState {
/// we may need to know who's our current consumer.
/// This is mostly for hover handler (where we render markup)
fn get_content_consumer_type(&self) -> ContentConsumerType;

fn ensure_documents_are_synced(&self);
}

/// This structure contains all available resources that we may use in the Relay LSP message/notification
Expand All @@ -163,8 +159,6 @@ pub struct LSPState<
pub(crate) notify_lsp_state_resources: Arc<Notify>,
pub(crate) project_status: ProjectStatusMap,
js_resource: Option<Box<dyn JSLanguageServer<TState = Self>>>,
is_syncing: Mutex<bool>,
is_syncing_condvar: Condvar,
}

impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentation>
Expand Down Expand Up @@ -206,8 +200,6 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
source_programs: Arc::new(DashMap::with_hasher(FnvBuildHasher::default())),
synced_javascript_features: Default::default(),
js_resource,
is_syncing: Mutex::new(false),
is_syncing_condvar: Condvar::new(),
};

// Preload schema documentation - this will warm-up schema documentation cache in the LSP Extra Data providers
Expand Down Expand Up @@ -361,13 +353,6 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
self.diagnostic_reporter
.clear_quick_diagnostics_for_url(url);
}

fn set_is_syncing(&self, value: bool) {
let mut is_syncing = self.is_syncing.lock().unwrap();

*is_syncing = value;
self.is_syncing_condvar.notify_all();
}
}

impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentation + 'static>
Expand Down Expand Up @@ -517,45 +502,32 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
}

fn document_opened(&self, uri: &Url, text: &str) -> LSPRuntimeResult<()> {
self.set_is_syncing(true);

if let Some(js_server) = self.get_js_language_sever() {
js_server.process_js_source(uri, text);
}

// First we check to see if this document has any GraphQL documents.
let embedded_sources = extract_graphql::extract(text);
let result = if embedded_sources.is_empty() {
if embedded_sources.is_empty() {
Ok(())
} else {
self.process_synced_sources(uri, embedded_sources)
};

self.set_is_syncing(false);

result
}
}

fn document_changed(&self, uri: &Url, full_text: &str) -> LSPRuntimeResult<()> {
self.set_is_syncing(true);

if let Some(js_server) = self.get_js_language_sever() {
js_server.process_js_source(uri, full_text);
}

// First we check to see if this document has any GraphQL documents.
let embedded_sources = extract_graphql::extract(full_text);
let result = if embedded_sources.is_empty() {
if embedded_sources.is_empty() {
self.remove_synced_sources(uri);

Ok(())
} else {
self.process_synced_sources(uri, embedded_sources)
};

self.set_is_syncing(false);

result
}
}

fn document_closed(&self, uri: &Url) -> LSPRuntimeResult<()> {
Expand All @@ -569,18 +541,6 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
fn get_content_consumer_type(&self) -> ContentConsumerType {
ContentConsumerType::Relay
}

fn ensure_documents_are_synced(&self) {
let mut is_syncing = self.is_syncing.lock().unwrap();

if *is_syncing {
debug!("waiting for document sync to complete");
}

while *is_syncing {
is_syncing = self.is_syncing_condvar.wait(is_syncing).unwrap();
}
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 3faf115

Please sign in to comment.