Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@ WIP!
- Route controller/form
- Hook references
- Permission references
- Plugin references
### Go to definition
- Service references
- Service class
- Route references
- Route controller/form
- Hook references
- Permission references
- Plugin references
### Completion
- Services
- Routes
- Hook snippets
- General snippets
- Snippets
- A few QoL improving snippets.
- Hooks
- form-[ELEMENT]
- render-[ELEMENT]
- Permissions
- Plugin IDs (limited to:)
- EntityType
- QueueWorker
- FieldType
- DataType
- FormElement
- RenderElement

## Installation

Expand Down Expand Up @@ -59,7 +71,6 @@ WIP!

## Roadmap
### Completion
- [ ] Autocomplete plugin IDs (eg. queue workers, blocks, fields, migrate source/process/destination).
- [ ] Autocomplete #theme functions.

### Code actions
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<()> {
builder.init();
log::trace!("log options: {:?}", config);

match start_lsp().await {
match start_lsp(config).await {
Ok(_) => (),
Err(error) => log::error!("An unexpected error happened: {:?}", error),
};
Expand Down
18 changes: 18 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,22 @@ pub struct DrupalLspConfig {
/// Valid values are: TRACE, DEBUG, INFO, WARN, ERROR
#[clap(short, long, default_value = "INFO")]
pub level: String,

/// Uses stdio as the communication channel, will be as the default communication channel.
#[clap(short, long)]
pub stdio: bool,

/// Use pipes (Windows) or socket files (Linux, Mac) as the communication channel.
/// The pipe / socket file name is passed as the next arg or with --pipe=.
/// Unsupported for now!
#[clap(short, long)]
pub pipe: Option<String>,

/// Uses a socket as the communication channel. The port is passed as next arg or with --port=.
#[clap(short, long)]
pub socket: Option<u16>,

/// The port to use for the socket connection.
#[clap(short, long)]
pub port: Option<u16>,
}
16 changes: 12 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod handle_notification;
mod handle_request;
mod handlers;

use std::net::{Ipv4Addr, SocketAddrV4};
use std::vec;

use anyhow::Result;
Expand All @@ -12,6 +13,7 @@ use lsp_types::{
};

use crate::document_store::initialize_document_store;
use crate::opts::DrupalLspConfig;
use crate::utils::uri_to_url;

use self::handle_notification::handle_notification;
Expand All @@ -32,13 +34,19 @@ async fn main_loop(connection: Connection) {
}
}

pub async fn start_lsp() -> Result<()> {
pub async fn start_lsp(config: DrupalLspConfig) -> Result<()> {
// Note that we must have our logging only write out to stderr.
log::info!("Starting Drupal Language server");

// Create the transport. Includes the stdio (stdin and stdout) versions but this could
// also be implemented to use sockets or HTTP.
let (connection, io_threads) = Connection::stdio();
let (connection, io_threads);
if let Some(socket_port) = config.socket.or(config.port) {
(connection, io_threads) =
Connection::connect(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), socket_port))?;
} else if config.pipe.is_some() {
panic!("Unsupported transport type 'pipe'.");
} else {
(connection, io_threads) = Connection::stdio();
}

// Run the server and wait for the two threads to end (typically by trigger LSP Exit event).
let server_capabilities = serde_json::to_value(&ServerCapabilities {
Expand Down