<NME> lib.rs
<BEF> /*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#![deny(clippy::all)]

mod client;
mod code_action;
pub mod completion;
pub mod diagnostic_reporter;
mod lsp;
mod server;
mod text_documents;
use error::Result;
use log::info;
use lsp_server::Connection;
use relay_compiler::config::Config;

pub async fn start_language_server(config: Config) -> Result<()> {
    let (connection, io_handles) = Connection::stdio();
    info!("Initialized stdio transport layer");
    let params = server::initialize(&connection)?;
    info!("JSON-RPC handshake completed");
    server::run(connection, config, params).await?;
    io_handles.join()?;
    Ok(())
}
pub use extract_graphql::JavaScriptSourceFeature;
use graphql_syntax::ExecutableDocument;
pub use hover::ContentConsumerType;
pub use js_language_server::JSLanguageServer;
use log::debug;
pub use lsp_extra_data_provider::DummyExtraDataProvider;
pub use lsp_extra_data_provider::FieldDefinitionSourceInfo;
pub use lsp_extra_data_provider::FieldSchemaInfo;
pub use lsp_extra_data_provider::LSPExtraDataProvider;
use lsp_process_error::LSPProcessResult;
pub use lsp_runtime_error::LSPRuntimeError;
pub use lsp_runtime_error::LSPRuntimeResult;
use lsp_server::Connection;
use node_resolution_info::NodeResolutionInfo;
use relay_compiler::config::Config;
use relay_docblock::DocblockIr;
use schema_documentation::SchemaDocumentation;
use schema_documentation::SchemaDocumentationLoader;
pub use server::GlobalState;
pub use server::LSPNotificationDispatch;
pub use server::LSPRequestDispatch;
pub use server::LSPState;
pub use server::Schemas;
pub use utils::position_to_offset;

pub enum Feature {
    GraphQLDocument(ExecutableDocument),
    DocblockIr(DocblockIr),
}

#[allow(clippy::large_enum_variant)]
pub enum FeatureResolutionInfo {
    GraphqlNode(NodeResolutionInfo),
    DocblockNode(DocblockNode),
}

pub struct DocblockNode {
    resolution_info: DocblockResolutionInfo,
    ir: DocblockIr,
}

pub async fn start_language_server<
    TPerfLogger,
    TSchemaDocumentation: SchemaDocumentation + 'static,
>(
    config: Config,
    perf_logger: Arc<TPerfLogger>,
    extra_data_provider: Box<dyn LSPExtraDataProvider + Send + Sync>,
    schema_documentation_loader: Option<Box<dyn SchemaDocumentationLoader<TSchemaDocumentation>>>,
    js_language_server: Option<
        Box<dyn JSLanguageServer<TState = LSPState<TPerfLogger, TSchemaDocumentation>>>,
    >,
) -> LSPProcessResult<()>
where
    TPerfLogger: PerfLogger + 'static,
{
    let (connection, io_handles) = Connection::stdio();
    debug!("Initialized stdio transport layer");
    let params = server::initialize(&connection)?;
    debug!("JSON-RPC handshake completed");
    server::run(
        connection,
        config,
        params,
        perf_logger,
        extra_data_provider,
        schema_documentation_loader,
        js_language_server,
    )
    .await?;
    io_handles.join()?;
    Ok(())
}

#[cfg(test)]
mod tests {
    use lsp_server::Connection;
    use lsp_types::ClientCapabilities;
    use lsp_types::InitializeParams;

    use super::client;
    use super::lsp_process_error::LSPProcessResult;
    use super::server;
    #[test]
    fn initialize() -> LSPProcessResult<()> {
        // Test with an in-memory connection pair
        let (connection, client) = Connection::memory();
        // Mock set of client parameters. The `root_path` field is deprecated, but
        // still required to construct the params, so we allow deprecated fields here.
        #[allow(deprecated)]
        let init_params = InitializeParams {
            process_id: Some(1),
            root_path: None,
            root_uri: None,
            initialization_options: None,
            capabilities: ClientCapabilities::default(),
            trace: None,
            workspace_folders: None,
            client_info: None,
            locale: None,
        };
        client::initialize(&client, &init_params, 0);
        let params = server::initialize(&connection)?;
        assert_eq!(params, init_params);
        Ok(())
    }
}

<MSG> - pass perf_logger to LSP Server main loop

Reviewed By: rbalicki2

Differential Revision: D24649532

fbshipit-source-id: 830fcae54bec35a751fcb29b65f912ece564f7a4

<DFF> @@ -14,17 +14,25 @@ mod error_reporting;
 mod lsp;
 mod server;
 mod text_documents;
+use common::PerfLogger;
 use error::Result;
 use log::info;
 use lsp_server::Connection;
 use relay_compiler::config::Config;
+use std::sync::Arc;
 
-pub async fn start_language_server(config: Config) -> Result<()> {
+pub async fn start_language_server<TPerfLogger>(
+    config: Config,
+    perf_logger: Arc<TPerfLogger>,
+) -> Result<()>
+where
+    TPerfLogger: PerfLogger + 'static,
+{
     let (connection, io_handles) = Connection::stdio();
     info!("Initialized stdio transport layer");
     let params = server::initialize(&connection)?;
     info!("JSON-RPC handshake completed");
-    server::run(connection, config, params).await?;
+    server::run(connection, config, params, perf_logger).await?;
     io_handles.join()?;
     Ok(())
 }

{'addition_count': 10, 'commit_subject': '- pass perf_logger to LSP Server main loop', 'deletion_count': 2, 'file_extension': '.rs', 'lang': 'rs', 'license': 'mit', 'repo_name': 'facebook/relay'}