Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"request": "launch",
"name": "Debug clice",
"program": "${workspaceFolder}/build/Debug/bin/clice",
"args": ["server", "--mode", "socket", "--port", "50051"],
"args": ["serve", "--mode", "tcp", "--port", "50051"],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug clice (socket, RelWithDebInfo)",
"name": "Debug clice (tcp, RelWithDebInfo)",
"program": "${workspaceFolder}/build/RelWithDebInfo/bin/clice",
"args": ["server", "--mode", "socket", "--port", "50051"],
"args": ["serve", "--mode", "tcp", "--port", "50051"],
"cwd": "${workspaceFolder}"
},
{
Expand Down Expand Up @@ -44,7 +44,7 @@
"--extensionDevelopmentPath=${workspaceFolder}/editors/vscode"
],
"env": {
"CLICE_MODE": "socket"
"CLICE_MODE": "tcp"
},
"outFiles": ["${workspaceFolder}/editors/vscode/dist/**/*.js"],
"preLaunchTask": "npm: watch vscode ext"
Expand Down
22 changes: 6 additions & 16 deletions docs/en/dev/test-and-debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Equivalent to:

### Integration Tests

End-to-end tests that start a real clice server and communicate via LSP protocol.
End-to-end tests that start a real `clice serve` instance and communicate via LSP protocol.

```bash
pixi run integration-test # default RelWithDebInfo
Expand Down Expand Up @@ -79,24 +79,14 @@ Prerequisites outside the pixi env:

## Debug

If you want to attach a debugger to clice, start it in socket mode independently, then connect a client.
If you want to attach a debugger to clice, start it in tcp mode independently, then connect a client.

```shell
./build/Debug/bin/clice server --mode socket --port 50051
./build/Debug/bin/clice serve --mode tcp --port 50051
```

After the server starts, you can connect a client in two ways:

### Connect via pytest

Run a single integration test against the running instance:

```shell
pytest -s --log-cli-level=INFO \
tests/integration/lifecycle/test_file_operation.py::test_did_open \
--mode=socket --port=50051
```

### Connect via VS Code

Configure the clice extension to connect to your running instance:
Expand All @@ -108,7 +98,7 @@ Configure the clice extension to connect to your running instance:
```jsonc
{
"clice.executable": "/path/to/your/clice/executable",
"clice.mode": "socket",
"clice.mode": "tcp",
"clice.port": 50051,
// Optional: disable clangd if also installed
"clangd.path": "",
Expand All @@ -130,6 +120,6 @@ The extension lives in-tree at `editors/vscode/`:

2. Open the **repository root** in VS Code (the launch configurations are in `.vscode/launch.json` at the root).

3. Create `.vscode/settings.json` with the socket config above.
3. Create `.vscode/settings.json` with the tcp config above.

4. Press `F5` and select `VSCode Extension (pipe)` or `VSCode Extension (socket)` to launch an Extension Development Host window.
4. Press `F5` and select `VSCode Extension (pipe)` or `VSCode Extension (tcp)` to launch an Extension Development Host window.
8 changes: 4 additions & 4 deletions docs/en/guide/editors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Add to `~/.config/helix/languages.toml`:
```toml
[language-server.clice]
command = "clice"
args = ["server"]
args = ["serve"]

[[language]]
name = "cpp"
Expand All @@ -53,7 +53,7 @@ With the built-in eglot:
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'((c-mode c-ts-mode c++-mode c++-ts-mode)
. ("clice" "server"))))
. ("clice" "serve"))))
```

### Sublime Text
Expand All @@ -65,7 +65,7 @@ Install the [LSP package](https://packagecontrol.io/packages/LSP), then add to i
"clients": {
"clice": {
"enabled": true,
"command": ["clice", "server"],
"command": ["clice", "serve"],
"selector": "source.c | source.c++"
}
}
Expand All @@ -80,7 +80,7 @@ Open `Settings → Configure Kate → LSP Client → User Server Settings` and a
{
"servers": {
"c": {
"command": ["clice", "server"],
"command": ["clice", "serve"],
"url": "https://github.com/clice-io/clice",
"highlightingModeRegex": "^(C|C\\+\\+)$"
}
Expand Down
18 changes: 4 additions & 14 deletions docs/zh/dev/test-and-debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,14 @@ pixi 环境之外的依赖:

## 调试

如果想在 clice 上附加调试器,推荐先以 socket 模式单独启动 clice,然后连接客户端。
如果想在 clice 上附加调试器,推荐先以 tcp 模式单独启动 clice,然后连接客户端。

```shell
./build/Debug/bin/clice server --mode socket --port 50051
./build/Debug/bin/clice serve --mode tcp --port 50051
```

服务器启动后,可以通过以下两种方式连接客户端:

### 通过 pytest 连接

运行单个集成测试连接到正在运行的 clice 实例:

```shell
pytest -s --log-cli-level=INFO \
tests/integration/lifecycle/test_file_operation.py::test_did_open \
--mode=socket --port=50051
```

### 通过 VS Code 连接

配置 clice 插件连接到正在运行的实例:
Expand All @@ -108,7 +98,7 @@ pytest -s --log-cli-level=INFO \
```jsonc
{
"clice.executable": "/path/to/your/clice/executable",
"clice.mode": "socket",
"clice.mode": "tcp",
"clice.port": 50051,
// 可选:禁用 clangd
"clangd.path": "",
Expand All @@ -130,6 +120,6 @@ pytest -s --log-cli-level=INFO \

2. 用 VS Code 打开 `editors/vscode`。

3. 创建上述 socket 配置的 `.vscode/settings.json`。
3. 创建上述 tcp 配置的 `.vscode/settings.json`。

4. 按 `F5` 启动扩展开发宿主窗口。
8 changes: 4 additions & 4 deletions docs/zh/guide/editors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Zed 扩展位于 [`editors/zed`](https://github.com/clice-io/clice/tree/main/edi
```toml
[language-server.clice]
command = "clice"
args = ["server"]
args = ["serve"]

[[language]]
name = "cpp"
Expand All @@ -53,7 +53,7 @@ language-servers = ["clice"]
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'((c-mode c-ts-mode c++-mode c++-ts-mode)
. ("clice" "server"))))
. ("clice" "serve"))))
```

### Sublime Text
Expand All @@ -65,7 +65,7 @@ language-servers = ["clice"]
"clients": {
"clice": {
"enabled": true,
"command": ["clice", "server"],
"command": ["clice", "serve"],
"selector": "source.c | source.c++"
}
}
Expand All @@ -80,7 +80,7 @@ language-servers = ["clice"]
{
"servers": {
"c": {
"command": ["clice", "server"],
"command": ["clice", "serve"],
"url": "https://github.com/clice-io/clice",
"highlightingModeRegex": "^(C|C\\+\\+)$"
}
Expand Down
2 changes: 1 addition & 1 deletion editors/nvim/doc/clice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local clice = {

cmd = {
'clice',
'server',
'serve',
},
}

Expand Down
2 changes: 1 addition & 1 deletion editors/nvim/tests/e2e.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end
local plugin_root = vim.fn.fnamemodify(arg[0], ':p:h:h')
local config = dofile(plugin_root .. '/doc/clice.lua')
config.name = 'clice'
config.cmd = { clice_path, 'server' }
config.cmd = { clice_path, 'serve' }
config.root_dir = fixture_dir

local main_file_uri = vim.uri_from_fname(fixture_dir .. '/' .. scenario.file)
Expand Down
4 changes: 2 additions & 2 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"default": "pipe",
"enum": [
"pipe",
"socket"
"tcp"
],
"description": "How to communicate with clice. pipe or socket. For daily use please use pipe."
"description": "How to communicate with clice. pipe (default) or tcp (debug)."
},
"clice.host": {
"type": "string",
Expand Down
6 changes: 3 additions & 3 deletions editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export async function activate(context: ExtensionContext) {
}
}

let args = ["server"];
let args = ["serve"];
serverOptions = {
run: { command: executable, args: args },
debug: { command: executable, args: args },
};
} else if (setting.mode === "socket") {
} else if (setting.mode === "tcp") {
serverOptions = (): Promise<StreamInfo> => {
return new Promise((resolve, reject) => {
const client = new net.Socket();
Expand All @@ -66,7 +66,7 @@ export async function activate(context: ExtensionContext) {
});
};
} else {
vscode.window.showErrorMessage("Invalid mode, please set the mode to 'pipe' or 'socket'.");
vscode.window.showErrorMessage("Invalid mode, please set the mode to 'pipe' or 'tcp'.");
return;
}

Expand Down
9 changes: 5 additions & 4 deletions editors/vscode/src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ interface Setting {
export function getSetting(): Setting | undefined {
const setting = vscode.workspace.getConfiguration("clice");
const executable = process.env.CLICE_EXECUTABLE || setting.get<string>("executable");
const mode = process.env.CLICE_MODE || setting.get<string>("mode");
const configuredMode = process.env.CLICE_MODE || setting.get<string>("mode");
const mode = configuredMode === "socket" ? "tcp" : configuredMode;

if (mode !== "pipe" && mode !== "socket") {
if (mode !== "pipe" && mode !== "tcp") {
vscode.window.showErrorMessage(`Unexpected mode: ${mode}`);
return undefined;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const host = setting.get<string>("host")!;
const port = setting.get<number>("port")!;

if (mode === "socket" && (!host || !port)) {
vscode.window.showErrorMessage("Socket mode requires both host and port to be configured.");
if (mode === "tcp" && (!host || !port)) {
vscode.window.showErrorMessage("TCP mode requires both host and port to be configured.");
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion editors/zed/src/clice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl zed::Extension for CliceExtension {
Ok(zed::Command {
command: binary.path,
args: vec![
"server".to_string(),
"serve".to_string(),
],
env: Default::default(),
})
Expand Down
23 changes: 5 additions & 18 deletions src/clice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,17 @@ int main(int argc, const char** argv) {

int exit_code = 1;

auto server_cmd = deco::cli::command<clice::ServerOptions>("clice server [OPTIONS]");
server_cmd
auto serve_cmd = deco::cli::command<clice::ServerOptions>("clice serve [OPTIONS]");
serve_cmd
.matchAll([&](clice::ServerOptions opts) {
if(opts.help) {
clice::print_usage(server_cmd);
clice::print_usage(serve_cmd);
exit_code = 0;
return;
}
if(!clice::apply_log_level(opts.log_level.value_or("info")))
return;
using clice::ServerMode;
auto mode = opts.mode.value_or(ServerMode::Pipe);
if(mode == ServerMode::Relay) {
exit_code = clice::run_relay_mode(opts.socket.value_or(""));
} else if(mode == ServerMode::Daemon) {
auto workspace = opts.workspace.value_or("");
if(workspace.empty()) {
LOG_ERROR("--workspace is required for daemon mode");
return;
}
exit_code = clice::run_daemon_mode(opts, self_path);
} else {
exit_code = clice::run_server_mode(opts, self_path);
}
exit_code = clice::run_serve_mode(opts, self_path);
})
.on_error([](auto err) { LOG_ERROR("{}", err.message); });

Expand Down Expand Up @@ -181,7 +168,7 @@ int main(int argc, const char** argv) {
clice::print_usage(clice);
};

clice.add({.name = "server", .description = "Start LSP server"}, server_cmd)
clice.add({.name = "serve", .description = "Start LSP server"}, serve_cmd)
Comment thread
16bit-ykiko marked this conversation as resolved.
Resolved
Comment thread
16bit-ykiko marked this conversation as resolved.
Resolved
.add({.name = "query", .description = "Query symbol information from a running server"},
query_cmd)
.add({.name = "worker"}, worker_cmd)
Expand Down
45 changes: 0 additions & 45 deletions src/server/service/agentic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string>

#include "server/protocol/agentic.h"
#include "support/filesystem.h"
#include "support/logging.h"

#include "kota/async/async.h"
Expand Down Expand Up @@ -126,48 +125,4 @@ int run_agentic_mode(const QueryOptions& opts) {
return exit_code;
}

static kota::task<> relay_forward(kota::ipc::Transport& from, kota::ipc::Transport& to) {
while(true) {
auto msg = co_await from.read_message();
if(!msg)
break;
co_await to.write_message(*msg);
}
to.close();
}

static kota::task<> relay_main(kota::event_loop& loop, int& exit_code, std::string socket_path) {
auto stdio = kota::ipc::StreamTransport::open_stdio(loop);
if(!stdio) {
LOG_ERROR("failed to open stdio transport");
loop.stop();
co_return;
}

auto conn = co_await kota::pipe::connect(socket_path, {}, loop);
if(!conn) {
LOG_ERROR("failed to connect to {}", socket_path);
loop.stop();
co_return;
}

auto socket = std::make_unique<kota::ipc::StreamTransport>(std::move(*conn));

co_await kota::when_all(relay_forward(**stdio, *socket), relay_forward(*socket, **stdio));
exit_code = 0;
loop.stop();
}

int run_relay_mode(llvm::StringRef socket_path) {
logging::stderr_logger("relay", logging::options);

auto path = socket_path.empty() ? path::default_socket_path() : socket_path.str();

kota::event_loop loop;
int exit_code = 1;
loop.schedule(relay_main(loop, exit_code, std::move(path)));
loop.run();
return exit_code;
}

} // namespace clice
2 changes: 0 additions & 2 deletions src/server/service/agentic.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,4 @@ struct QueryOptions {

int run_agentic_mode(const QueryOptions& opts);

int run_relay_mode(llvm::StringRef socket_path);

} // namespace clice
Loading
Loading