Conversation
fb02ca5 to
5c12d11
Compare
| # This image ships an older Cargo, so pin Rust 1.86.0 here for edition 2024 support. | ||
| rustup install 1.86.0 && | ||
| rustup default 1.86.0 && | ||
| # This image ships an older Cargo, so pin Rust 1.88.0 here for edition 2024 support. | ||
| rustup install 1.88.0 && | ||
| rustup default 1.88.0 && |
There was a problem hiding this comment.
language server クレートで利用している let chains のビルドに失敗するため 1.88.0 にアップデートしました
There was a problem hiding this comment.
language server と関係ない差分ですが、 clippy に指摘されていたため修正しました
https://rust-lang.github.io/rust-clippy/rust-1.95.0/index.html#collapsible_match
Add uroborosql-language-server crate implementing LSP over stdio. Supports textDocument/formatting, textDocument/rangeFormatting, and save-triggered lint diagnostics via uroborosql-lint.
Add run_language_server() NAPI function that starts the Rust language server over stdio using a multi-thread tokio runtime, and export it as runLanguageServer() from the npm package.
b7e4066 to
b276ef8
Compare
| doc.version = version; | ||
| if let Some(range) = change.range { | ||
| if let Some((start, end)) = rope_range_to_char_range(&doc.rope, &range) { | ||
| doc.rope.remove(start..end); | ||
| doc.rope.insert(start, &change.text); | ||
| } | ||
| } else { | ||
| doc.rope = Rope::from_str(&change.text); | ||
| } |
There was a problem hiding this comment.
rope_range_to_char_range() が失敗してNoneを返した場合、ropeの状態と doc.version の齟齬が発生し、その場合に publish_diagnostics の診断が不正になりそうです。
以下のようにしてropeが正常に更新された場合のみversionを更新するのはいかがでしょうか?
if let Some(range) = change.range {
if let Some((start, end)) = rope_range_to_char_range(&doc.rope, &range) {
doc.rope.remove(start..end);
doc.rope.insert(start, &change.text);
doc.version = version;
}
} else {
doc.rope = Rope::from_str(&change.text);
doc.version = version;
}There was a problem hiding this comment.
ありがとうございます。 rope の更新が成功した場合のみ doc.version を更新するよう修正しました。
| .await; | ||
| return; | ||
| }; | ||
|
|
There was a problem hiding this comment.
(現状はVSCodeのみ対応すると思うので優先度低です)
Neovim等のクライアントはconfigが設定されていない場合に received_config がnullになることがあるようです。
なので、以下のようにnullであればdefaultを返す処理を入れても良いかもしれないです。
if received_config.is_null() {
*self.client_config.write().unwrap() = ClientConfig::default();
return;
}There was a problem hiding this comment.
ありがとうございます。フォールバックはあったほうが良いと思ったので、 received_config.is_null() の場合に ClientConfig::default() を返す処理を追加しました。
| version: i32, | ||
| } | ||
|
|
||
| pub(crate) fn rope_position_to_char(rope: &Rope, position: Position) -> Option<usize> { |
There was a problem hiding this comment.
to_charで関数名が終わるとcharに変換して返すのかと思ってしまうので、char_indexのように明示したいです。
以下もあわせて変えたいです。
- rope_position_to_char
- rope_char_to_position
- rope_range_to_char_range
There was a problem hiding this comment.
それぞれ、rope_position_to_char_index、rope_char_index_to_position、rope_range_to_char_index_range に改名しました。
| }, | ||
| server_info: Some(ServerInfo { | ||
| name: "uroborosql-language-server".into(), | ||
| version: None, |
There was a problem hiding this comment.
以下のようにバージョン指定しておきませんか。
不具合報告の際にも、ユーザーが利用しているバージョンも追いやすくなるかなと。
version: Some(env!("CARGO_PKG_VERSION").into()),
There was a problem hiding this comment.
バージョン情報を指定するよう修正しました。
|
|
||
| let registrations = vec![Registration { | ||
| id: "uroborosql-fmt-watcher".to_string(), | ||
| method: "workspace/didChangeWatchedFiles".to_string(), |
There was a problem hiding this comment.
文字列を自分で書かずに、以下のように書けるようです。
method: DidChangeWatchedFiles::METHOD.to_string(),
There was a problem hiding this comment.
同様に修正しました。
| #[serde(rename_all(serialize = "snake_case", deserialize = "camelCase"))] | ||
| pub(crate) struct ClientConfig { | ||
| pub debug: Option<bool>, | ||
| pub tab_size: Option<usize>, |
There was a problem hiding this comment.
フォーマッター本体で定義しているConfigと被りがあるのが気になりました。
可能ならうまく集約したいです
3e1bfd1 to
6977d3b
Compare
…sion - handle null received_config from clients like Neovim - replace expect() with if-let in resolve_config_path - expose CARGO_PKG_VERSION in server_info
- ClientConfig の formatter フィールドに PartialConfig を flatten で埋め込み、フィールド重複を解消 - rename_all を廃止し alias 方式に統一(flatten との干渉を回避) - client_config_json_explicit_only を PartialConfig の直接 serialize に簡素化
6977d3b to
38d385f
Compare
|
@tanzaku. config の重複解消について、以下のように変更しました。 config の変更について
変更前は language server が 【変更前】
【変更後】
副作用現状では、 CLI や設定ファイルで camelCase のキーを受け付けるように なりました。 既存の動作への破壊的変更はありませんが、この変更については意見があればいただきたいです。 |
対応ありがとうございます。
|
Summary
LSP の言語サーバを実装しました。
Node-API 版にサーバ実装を追加しています。
主なライブラリとして以下を追加しています:
言語サーバの機能
publishDiagnostics).uroborosqlfmtrc.json/.uroborosqllintrc.jsonまたは 明示指定されたパス制限
フォーマット機能について
現状の言語サーバは最低限の lint による検査とフォーマット処理を実装しています。
VS Code 上において、SQL ファイルの 1. 全文フォーマットおよび 2. 選択箇所のフォーマット はそれぞれ 1.
Format Document, 2.Format Selectionコマンドで実行可能になります。一方、現状の実装では SQL 以外の言語のファイルに(埋め込まれたSQLへ)対するフォーマットは動作しません。
そちらについてはLSP のカスタムコマンドを実装して実現しようと考えています。(別 PR で対応します)
また、そのタイミングで
uroborosql-fmt-napicrate で公開しているrunfmt()およびrunfmt_with_settings()が不要となるため削除する予定です。Note