Metadata-Version: 2.4
Name: kompas3d-lsp
Version: 0.2.0
Summary: LSP server for KOMPAS-3D ksAPI
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: pygls>=2.1.0
Requires-Dist: lsprotocol>=2025.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Provides-Extra: pyinstaller
Requires-Dist: pyinstaller>=6.0; extra == "pyinstaller"

# KOMPAS-3D LSP

**Language Server Protocol** server for **KOMPAS-3D ksAPI**.

Auto-completion, hover docs, signature help and diagnostics for KOMPAS-3D scripting in Python, C++ and C#.

Powered by the official ksAPI documentation — 856 interfaces, 7104 methods (RU), 54 interfaces (EN). Multi-language syntax: C++, Python (pywin32), C# (COM interop). No KOMPAS-3D installation required.

---

## Features

| Feature | Status |
|---------|--------|
| `textDocument/completion` — interfaces, methods, enum constants, per-language syntax | + |
| `textDocument/hover` — descriptions with syntax and examples per language | + |
| `textDocument/signatureHelp` — method signatures on argument input | + |
| `textDocument/publishDiagnostics` — common mistake warnings per language | + |
| `--check` batch mode — file validation without LSP | + |

---

## Installation

```bash
pip install kompas3d-lsp
```

Verify:

```bash
kompas3d-lsp --help
```

---

## OpenCode Integration

Put `opencode.json` in your project root:

```json
{
  "lsp": {
    "kompas3d-lsp": {
      "command": ["kompas3d-lsp", "--stdio"],
      "extensions": [".py", ".cpp", ".h", ".cs"]
    }
  }
}
```

---

## Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `KOMPAS_LSP_LANG` | `ru` | Knowledge base language (`ru` / `en`) |
| `KOMPAS_LSP_DATA_DIR` | — | Custom path to `{lang}/ksapi_knowledge.json` |

In `opencode.json`:

```json
{
  "lsp": {
    "kompas3d-lsp": {
      "command": ["kompas3d-lsp", "--stdio"],
      "extensions": [".py"],
      "env": { "KOMPAS_LSP_LANG": "en" }
    }
  }
}
```

---

## CLI

```
kompas3d-lsp --stdio              # stdio transport (default, for LSP clients)
kompas3d-lsp --tcp                # TCP transport (127.0.0.1:2087, debugging)
kompas3d-lsp --lang en            # override knowledge base language
kompas3d-lsp --check file.py      # batch file check (without LSP)
kompas3d-lsp --check file.py --json  # JSON output
kompas3d-lsp --help
```

---

## Supported Languages

| Extension | Language | Syntax Style |
|-----------|----------|-------------|
| `.py`, `.pyw` | Python | `method(param: type) -> type` |
| `.cpp`, `.cxx`, `.cc`, `.h`, `.hpp`, `.hxx` | C++ | Native from documentation |
| `.cs` | C# | `Type method(params);` |

Language auto-detected by file extension. Server shows syntax, examples and diagnostics matching the file language.

---

## Diagnostics

The server warns about:

1. **Python**: `import win32com.client` without `try/except` — KOMPAS may be missing on CI
2. **C++**: method call via `->` without null check
3. **C#**: `Marshal.GetActiveObject` / `Type.GetTypeFromProgID` without `try/catch`

---

## Client Configuration

### VS Code

```json
{
  "lsp.clients.kompas3d-lsp.command": ["kompas3d-lsp", "--stdio"]
}
```

### Neovim (vim.lsp)

```lua
vim.api.nvim_create_autocmd("FileType", {
  pattern = "python",
  callback = function()
    vim.lsp.start({
      name = "kompas3d-lsp",
      cmd = { "kompas3d-lsp", "--stdio" },
    })
  end,
})
```

---

## Links

- [KOMPAS-3D SDK Documentation](https://help.ascon.ru/KOMPAS_SDK/25/ru-RU/index.html)
- [LSP Specification](https://microsoft.github.io/language-server-protocol/)
- [pygls](https://github.com/openlawlibrary/pygls)

---

## License

MIT
