There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
366 lines
9.8 KiB
Rust
366 lines
9.8 KiB
Rust
use crate::{lsp_command::LspCommand, lsp_store::LspStore, make_text_document_identifier};
|
|
use anyhow::{Context as _, Result};
|
|
use async_trait::async_trait;
|
|
use gpui::{App, AsyncAppContext, Entity};
|
|
use language::{point_to_lsp, proto::deserialize_anchor, Buffer};
|
|
use lsp::{LanguageServer, LanguageServerId};
|
|
use rpc::proto::{self, PeerId};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::{path::Path, sync::Arc};
|
|
use text::{BufferId, PointUtf16, ToPointUtf16};
|
|
|
|
pub enum LspExpandMacro {}
|
|
|
|
impl lsp::request::Request for LspExpandMacro {
|
|
type Params = ExpandMacroParams;
|
|
type Result = Option<ExpandedMacro>;
|
|
const METHOD: &'static str = "rust-analyzer/expandMacro";
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct ExpandMacroParams {
|
|
pub text_document: lsp::TextDocumentIdentifier,
|
|
pub position: lsp::Position,
|
|
}
|
|
|
|
#[derive(Default, Deserialize, Serialize, Debug)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct ExpandedMacro {
|
|
pub name: String,
|
|
pub expansion: String,
|
|
}
|
|
|
|
impl ExpandedMacro {
|
|
pub fn is_empty(&self) -> bool {
|
|
self.name.is_empty() && self.expansion.is_empty()
|
|
}
|
|
}
|
|
#[derive(Debug)]
|
|
pub struct ExpandMacro {
|
|
pub position: PointUtf16,
|
|
}
|
|
|
|
#[async_trait(?Send)]
|
|
impl LspCommand for ExpandMacro {
|
|
type Response = ExpandedMacro;
|
|
type LspRequest = LspExpandMacro;
|
|
type ProtoRequest = proto::LspExtExpandMacro;
|
|
|
|
fn display_name(&self) -> &str {
|
|
"Expand macro"
|
|
}
|
|
|
|
fn to_lsp(
|
|
&self,
|
|
path: &Path,
|
|
_: &Buffer,
|
|
_: &Arc<LanguageServer>,
|
|
_: &App,
|
|
) -> Result<ExpandMacroParams> {
|
|
Ok(ExpandMacroParams {
|
|
text_document: make_text_document_identifier(path)?,
|
|
position: point_to_lsp(self.position),
|
|
})
|
|
}
|
|
|
|
async fn response_from_lsp(
|
|
self,
|
|
message: Option<ExpandedMacro>,
|
|
_: Entity<LspStore>,
|
|
_: Entity<Buffer>,
|
|
_: LanguageServerId,
|
|
_: AsyncAppContext,
|
|
) -> anyhow::Result<ExpandedMacro> {
|
|
Ok(message
|
|
.map(|message| ExpandedMacro {
|
|
name: message.name,
|
|
expansion: message.expansion,
|
|
})
|
|
.unwrap_or_default())
|
|
}
|
|
|
|
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::LspExtExpandMacro {
|
|
proto::LspExtExpandMacro {
|
|
project_id,
|
|
buffer_id: buffer.remote_id().into(),
|
|
position: Some(language::proto::serialize_anchor(
|
|
&buffer.anchor_before(self.position),
|
|
)),
|
|
}
|
|
}
|
|
|
|
async fn from_proto(
|
|
message: Self::ProtoRequest,
|
|
_: Entity<LspStore>,
|
|
buffer: Entity<Buffer>,
|
|
mut cx: AsyncAppContext,
|
|
) -> anyhow::Result<Self> {
|
|
let position = message
|
|
.position
|
|
.and_then(deserialize_anchor)
|
|
.context("invalid position")?;
|
|
Ok(Self {
|
|
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
|
|
})
|
|
}
|
|
|
|
fn response_to_proto(
|
|
response: ExpandedMacro,
|
|
_: &mut LspStore,
|
|
_: PeerId,
|
|
_: &clock::Global,
|
|
_: &mut App,
|
|
) -> proto::LspExtExpandMacroResponse {
|
|
proto::LspExtExpandMacroResponse {
|
|
name: response.name,
|
|
expansion: response.expansion,
|
|
}
|
|
}
|
|
|
|
async fn response_from_proto(
|
|
self,
|
|
message: proto::LspExtExpandMacroResponse,
|
|
_: Entity<LspStore>,
|
|
_: Entity<Buffer>,
|
|
_: AsyncAppContext,
|
|
) -> anyhow::Result<ExpandedMacro> {
|
|
Ok(ExpandedMacro {
|
|
name: message.name,
|
|
expansion: message.expansion,
|
|
})
|
|
}
|
|
|
|
fn buffer_id_from_proto(message: &proto::LspExtExpandMacro) -> Result<BufferId> {
|
|
BufferId::new(message.buffer_id)
|
|
}
|
|
}
|
|
|
|
pub enum LspOpenDocs {}
|
|
|
|
impl lsp::request::Request for LspOpenDocs {
|
|
type Params = OpenDocsParams;
|
|
type Result = Option<DocsUrls>;
|
|
const METHOD: &'static str = "experimental/externalDocs";
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct OpenDocsParams {
|
|
pub text_document: lsp::TextDocumentIdentifier,
|
|
pub position: lsp::Position,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct DocsUrls {
|
|
pub web: Option<String>,
|
|
pub local: Option<String>,
|
|
}
|
|
|
|
impl DocsUrls {
|
|
pub fn is_empty(&self) -> bool {
|
|
self.web.is_none() && self.local.is_none()
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct OpenDocs {
|
|
pub position: PointUtf16,
|
|
}
|
|
|
|
#[async_trait(?Send)]
|
|
impl LspCommand for OpenDocs {
|
|
type Response = DocsUrls;
|
|
type LspRequest = LspOpenDocs;
|
|
type ProtoRequest = proto::LspExtOpenDocs;
|
|
|
|
fn display_name(&self) -> &str {
|
|
"Open docs"
|
|
}
|
|
|
|
fn to_lsp(
|
|
&self,
|
|
path: &Path,
|
|
_: &Buffer,
|
|
_: &Arc<LanguageServer>,
|
|
_: &App,
|
|
) -> Result<OpenDocsParams> {
|
|
Ok(OpenDocsParams {
|
|
text_document: lsp::TextDocumentIdentifier {
|
|
uri: lsp::Url::from_file_path(path).unwrap(),
|
|
},
|
|
position: point_to_lsp(self.position),
|
|
})
|
|
}
|
|
|
|
async fn response_from_lsp(
|
|
self,
|
|
message: Option<DocsUrls>,
|
|
_: Entity<LspStore>,
|
|
_: Entity<Buffer>,
|
|
_: LanguageServerId,
|
|
_: AsyncAppContext,
|
|
) -> anyhow::Result<DocsUrls> {
|
|
Ok(message
|
|
.map(|message| DocsUrls {
|
|
web: message.web,
|
|
local: message.local,
|
|
})
|
|
.unwrap_or_default())
|
|
}
|
|
|
|
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::LspExtOpenDocs {
|
|
proto::LspExtOpenDocs {
|
|
project_id,
|
|
buffer_id: buffer.remote_id().into(),
|
|
position: Some(language::proto::serialize_anchor(
|
|
&buffer.anchor_before(self.position),
|
|
)),
|
|
}
|
|
}
|
|
|
|
async fn from_proto(
|
|
message: Self::ProtoRequest,
|
|
_: Entity<LspStore>,
|
|
buffer: Entity<Buffer>,
|
|
mut cx: AsyncAppContext,
|
|
) -> anyhow::Result<Self> {
|
|
let position = message
|
|
.position
|
|
.and_then(deserialize_anchor)
|
|
.context("invalid position")?;
|
|
Ok(Self {
|
|
position: buffer.update(&mut cx, |buffer, _| position.to_point_utf16(buffer))?,
|
|
})
|
|
}
|
|
|
|
fn response_to_proto(
|
|
response: DocsUrls,
|
|
_: &mut LspStore,
|
|
_: PeerId,
|
|
_: &clock::Global,
|
|
_: &mut App,
|
|
) -> proto::LspExtOpenDocsResponse {
|
|
proto::LspExtOpenDocsResponse {
|
|
web: response.web,
|
|
local: response.local,
|
|
}
|
|
}
|
|
|
|
async fn response_from_proto(
|
|
self,
|
|
message: proto::LspExtOpenDocsResponse,
|
|
_: Entity<LspStore>,
|
|
_: Entity<Buffer>,
|
|
_: AsyncAppContext,
|
|
) -> anyhow::Result<DocsUrls> {
|
|
Ok(DocsUrls {
|
|
web: message.web,
|
|
local: message.local,
|
|
})
|
|
}
|
|
|
|
fn buffer_id_from_proto(message: &proto::LspExtOpenDocs) -> Result<BufferId> {
|
|
BufferId::new(message.buffer_id)
|
|
}
|
|
}
|
|
|
|
pub enum LspSwitchSourceHeader {}
|
|
|
|
impl lsp::request::Request for LspSwitchSourceHeader {
|
|
type Params = SwitchSourceHeaderParams;
|
|
type Result = Option<SwitchSourceHeaderResult>;
|
|
const METHOD: &'static str = "textDocument/switchSourceHeader";
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct SwitchSourceHeaderParams(lsp::TextDocumentIdentifier);
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct SwitchSourceHeaderResult(pub String);
|
|
|
|
#[derive(Default, Deserialize, Serialize, Debug)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct SwitchSourceHeader;
|
|
|
|
#[async_trait(?Send)]
|
|
impl LspCommand for SwitchSourceHeader {
|
|
type Response = SwitchSourceHeaderResult;
|
|
type LspRequest = LspSwitchSourceHeader;
|
|
type ProtoRequest = proto::LspExtSwitchSourceHeader;
|
|
|
|
fn display_name(&self) -> &str {
|
|
"Switch source header"
|
|
}
|
|
|
|
fn to_lsp(
|
|
&self,
|
|
path: &Path,
|
|
_: &Buffer,
|
|
_: &Arc<LanguageServer>,
|
|
_: &App,
|
|
) -> Result<SwitchSourceHeaderParams> {
|
|
Ok(SwitchSourceHeaderParams(make_text_document_identifier(
|
|
path,
|
|
)?))
|
|
}
|
|
|
|
async fn response_from_lsp(
|
|
self,
|
|
message: Option<SwitchSourceHeaderResult>,
|
|
_: Entity<LspStore>,
|
|
_: Entity<Buffer>,
|
|
_: LanguageServerId,
|
|
_: AsyncAppContext,
|
|
) -> anyhow::Result<SwitchSourceHeaderResult> {
|
|
Ok(message
|
|
.map(|message| SwitchSourceHeaderResult(message.0))
|
|
.unwrap_or_default())
|
|
}
|
|
|
|
fn to_proto(&self, project_id: u64, buffer: &Buffer) -> proto::LspExtSwitchSourceHeader {
|
|
proto::LspExtSwitchSourceHeader {
|
|
project_id,
|
|
buffer_id: buffer.remote_id().into(),
|
|
}
|
|
}
|
|
|
|
async fn from_proto(
|
|
_: Self::ProtoRequest,
|
|
_: Entity<LspStore>,
|
|
_: Entity<Buffer>,
|
|
_: AsyncAppContext,
|
|
) -> anyhow::Result<Self> {
|
|
Ok(Self {})
|
|
}
|
|
|
|
fn response_to_proto(
|
|
response: SwitchSourceHeaderResult,
|
|
_: &mut LspStore,
|
|
_: PeerId,
|
|
_: &clock::Global,
|
|
_: &mut App,
|
|
) -> proto::LspExtSwitchSourceHeaderResponse {
|
|
proto::LspExtSwitchSourceHeaderResponse {
|
|
target_file: response.0,
|
|
}
|
|
}
|
|
|
|
async fn response_from_proto(
|
|
self,
|
|
message: proto::LspExtSwitchSourceHeaderResponse,
|
|
_: Entity<LspStore>,
|
|
_: Entity<Buffer>,
|
|
_: AsyncAppContext,
|
|
) -> anyhow::Result<SwitchSourceHeaderResult> {
|
|
Ok(SwitchSourceHeaderResult(message.target_file))
|
|
}
|
|
|
|
fn buffer_id_from_proto(message: &proto::LspExtSwitchSourceHeader) -> Result<BufferId> {
|
|
BufferId::new(message.buffer_id)
|
|
}
|
|
}
|