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
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo check

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test

fmt:
name: Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy -- -D warnings
56 changes: 27 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ impl LanguageServer for Backend {
async fn did_change(&self, params: DidChangeTextDocumentParams) {
let uri = params.text_document.uri.to_string();

if let Some(change) = params.content_changes.first() {
if let Ok(mut files) = self.open_files.lock() {
files.insert(uri, change.text.clone());
}
if let Some(change) = params.content_changes.first()
&& let Ok(mut files) = self.open_files.lock()
{
files.insert(uri, change.text.clone());
}
}

Expand All @@ -143,7 +143,11 @@ impl LanguageServer for Backend {
}

async fn hover(&self, params: HoverParams) -> Result<Option<Hover>> {
let uri = params.text_document_position_params.text_document.uri.to_string();
let uri = params
.text_document_position_params
.text_document
.uri
.to_string();
let position = params.text_document_position_params.position;

let content = if let Ok(files) = self.open_files.lock() {
Expand All @@ -152,34 +156,28 @@ impl LanguageServer for Backend {
None
};

if let Some(content) = content {
if let Some(word) = self.get_word_at_position(&content, position) {
if word == "PHPantom" {
return Ok(Some(Hover {
contents: HoverContents::Scalar(MarkedString::String(
"Welcome to PHPantomLSP!".to_string(),
)),
range: None,
}));
}
}
if let Some(content) = content
&& let Some(word) = self.get_word_at_position(&content, position)
&& word == "PHPantom"
{
return Ok(Some(Hover {
contents: HoverContents::Scalar(MarkedString::String(
"Welcome to PHPantomLSP!".to_string(),
)),
range: None,
}));
}

Ok(None)
}

async fn completion(
&self,
_params: CompletionParams,
) -> Result<Option<CompletionResponse>> {
Ok(Some(CompletionResponse::Array(vec![
CompletionItem {
label: "PHPantomLSP".to_string(),
kind: Some(CompletionItemKind::TEXT),
detail: Some("PHPantomLSP completion".to_string()),
insert_text: Some("PHPantomLSP".to_string()),
..CompletionItem::default()
},
])))
async fn completion(&self, _params: CompletionParams) -> Result<Option<CompletionResponse>> {
Ok(Some(CompletionResponse::Array(vec![CompletionItem {
label: "PHPantomLSP".to_string(),
kind: Some(CompletionItemKind::TEXT),
detail: Some("PHPantomLSP completion".to_string()),
insert_text: Some("PHPantomLSP".to_string()),
..CompletionItem::default()
}])))
}
}
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ async fn main() {
let stdin = tokio::io::stdin();
let stdout = tokio::io::stdout();

let (service, socket) = LspService::new(|client| Backend::new(client));
let (service, socket) = LspService::new(Backend::new);

Server::new(stdin, stdout, socket)
.serve(service)
.await;
Server::new(stdin, stdout, socket).serve(service).await;
}
2 changes: 1 addition & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use phpantom_lsp::Backend;
use tower_lsp::lsp_types::*;
use tower_lsp::LanguageServer;
use tower_lsp::lsp_types::*;

fn create_test_backend() -> Backend {
Backend::new_test()
Expand Down