Skip to content

Commit 5513c95

Browse files
committed
Add CI
1 parent 731abef commit 5513c95

4 files changed

Lines changed: 80 additions & 34 deletions

File tree

.github/workflows/ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
check:
14+
name: Check
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: dtolnay/rust-toolchain@stable
19+
- uses: Swatinem/rust-cache@v2
20+
- run: cargo check
21+
22+
test:
23+
name: Test
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: dtolnay/rust-toolchain@stable
28+
- uses: Swatinem/rust-cache@v2
29+
- run: cargo test
30+
31+
fmt:
32+
name: Formatting
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: dtolnay/rust-toolchain@stable
37+
with:
38+
components: rustfmt
39+
- run: cargo fmt --check
40+
41+
clippy:
42+
name: Clippy
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: dtolnay/rust-toolchain@stable
47+
with:
48+
components: clippy
49+
- uses: Swatinem/rust-cache@v2
50+
- run: cargo clippy -- -D warnings

src/lib.rs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ impl LanguageServer for Backend {
124124
async fn did_change(&self, params: DidChangeTextDocumentParams) {
125125
let uri = params.text_document.uri.to_string();
126126

127-
if let Some(change) = params.content_changes.first() {
128-
if let Ok(mut files) = self.open_files.lock() {
129-
files.insert(uri, change.text.clone());
130-
}
127+
if let Some(change) = params.content_changes.first()
128+
&& let Ok(mut files) = self.open_files.lock()
129+
{
130+
files.insert(uri, change.text.clone());
131131
}
132132
}
133133

@@ -143,7 +143,11 @@ impl LanguageServer for Backend {
143143
}
144144

145145
async fn hover(&self, params: HoverParams) -> Result<Option<Hover>> {
146-
let uri = params.text_document_position_params.text_document.uri.to_string();
146+
let uri = params
147+
.text_document_position_params
148+
.text_document
149+
.uri
150+
.to_string();
147151
let position = params.text_document_position_params.position;
148152

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

155-
if let Some(content) = content {
156-
if let Some(word) = self.get_word_at_position(&content, position) {
157-
if word == "PHPantom" {
158-
return Ok(Some(Hover {
159-
contents: HoverContents::Scalar(MarkedString::String(
160-
"Welcome to PHPantomLSP!".to_string(),
161-
)),
162-
range: None,
163-
}));
164-
}
165-
}
159+
if let Some(content) = content
160+
&& let Some(word) = self.get_word_at_position(&content, position)
161+
&& word == "PHPantom"
162+
{
163+
return Ok(Some(Hover {
164+
contents: HoverContents::Scalar(MarkedString::String(
165+
"Welcome to PHPantomLSP!".to_string(),
166+
)),
167+
range: None,
168+
}));
166169
}
167170

168171
Ok(None)
169172
}
170173

171-
async fn completion(
172-
&self,
173-
_params: CompletionParams,
174-
) -> Result<Option<CompletionResponse>> {
175-
Ok(Some(CompletionResponse::Array(vec![
176-
CompletionItem {
177-
label: "PHPantomLSP".to_string(),
178-
kind: Some(CompletionItemKind::TEXT),
179-
detail: Some("PHPantomLSP completion".to_string()),
180-
insert_text: Some("PHPantomLSP".to_string()),
181-
..CompletionItem::default()
182-
},
183-
])))
174+
async fn completion(&self, _params: CompletionParams) -> Result<Option<CompletionResponse>> {
175+
Ok(Some(CompletionResponse::Array(vec![CompletionItem {
176+
label: "PHPantomLSP".to_string(),
177+
kind: Some(CompletionItemKind::TEXT),
178+
detail: Some("PHPantomLSP completion".to_string()),
179+
insert_text: Some("PHPantomLSP".to_string()),
180+
..CompletionItem::default()
181+
}])))
184182
}
185183
}

src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ async fn main() {
88
let stdin = tokio::io::stdin();
99
let stdout = tokio::io::stdout();
1010

11-
let (service, socket) = LspService::new(|client| Backend::new(client));
11+
let (service, socket) = LspService::new(Backend::new);
1212

13-
Server::new(stdin, stdout, socket)
14-
.serve(service)
15-
.await;
13+
Server::new(stdin, stdout, socket).serve(service).await;
1614
}

tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use phpantom_lsp::Backend;
2-
use tower_lsp::lsp_types::*;
32
use tower_lsp::LanguageServer;
3+
use tower_lsp::lsp_types::*;
44

55
fn create_test_backend() -> Backend {
66
Backend::new_test()

0 commit comments

Comments
 (0)