Metadata-Version: 2.4
Name: rdflib-ontology-lsp
Version: 0.1.0
Summary: A pygls language server that autocompletes rdflib Namespace ontology terms in Python.
Project-URL: Homepage, https://github.com/SkIym/rdflib-ontology-lsp
Project-URL: Repository, https://github.com/SkIym/rdflib-ontology-lsp
Project-URL: Issues, https://github.com/SkIym/rdflib-ontology-lsp/issues
Author: rdflib-ontology-lsp contributors
License: MIT
License-File: LICENSE
Requires-Python: >=3.9
Requires-Dist: pygls>=2.0.0
Requires-Dist: rdflib>=6.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# RDFLib Ontology LSP

`rdflib-ontology-lsp` is a Python language server that adds autocomplete for `rdflib.Namespace` terms in Python files.

If your workspace contains:

```python
from rdflib import Namespace

SKG = Namespace("https://sakuna.ph/")
```

and an ontology file contains:

```turtle
@prefix skg: <https://sakuna.ph/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .

skg:Person a owl:Class .
skg:hasName a owl:DatatypeProperty .
skg:worksFor a owl:ObjectProperty .
```

then typing `SKG.` in a Python file can suggest `Person`, `hasName`, and `worksFor`.

## Features

- Scans Python files for `Namespace(...)`, `rdflib.Namespace(...)`, aliased imports such as `from rdflib import Namespace as NS`, and simple string constants passed to `Namespace(BASE_IRI)`.
- Scans ontology files matching `**/*.ttl`, `**/*.owl`, `**/*.rdf`, `**/*.nt`, and `**/*.jsonld`.
- Suggests only ontology local names that are valid Python dot-access identifiers.
- Includes the ontology type, full IRI, and source file in completion metadata.
- Shows `rdfs:comment` or `skos:definition` text in completion documentation when present.
- Refreshes the in-memory index when Python or ontology files change.
- Includes built-in suggestions for RDF, RDFS, SKOS, OWL, PROV-O, and GeoSPARQL namespace imports from RDFLib.

## Install

From this repository:

```bash
python -m pip install -e ".[dev]"
```

This installs the server and development test dependency. Runtime dependencies are `pygls` and `rdflib`.

## Run the Language Server

```bash
python -m rdflib_ontology_lsp.server
```

The server communicates over stdio, which is what the VS Code client uses.

## Run Tests

```bash
python -m pytest
```

## Example Files

The `examples/` directory contains:

- `examples/ontology.ttl`
- `examples/example.py`

They demonstrate the `https://sakuna.ph/` namespace and ontology terms.

## VS Code Extension Development

1. Install the Python server from the repository root:

   ```bash
   python -m pip install -e ".[dev]"
   ```

2. Install and build the VS Code client:

   ```bash
   cd vscode-client
   npm install
   npm run compile
   ```

3. Open this repository, or `vscode-client`, in VS Code.
4. Press `F5` to launch an Extension Development Host. The launch config opens this repository in the development host.
5. Type `SKG.` in `examples/example.py` after the detected `Namespace("https://sakuna.ph/")` assignment.

The client also adds the parent repository `src` directory to `PYTHONPATH` for local development, so it can run the server from source.

If suggestions do not appear automatically, run `Trigger Suggest` in VS Code or press `Ctrl+Space` after `SKG.`. Check `Output: RDFLib Ontology Autocomplete` for the Python executable, server cwd, and workspace scan messages.

## Configuration

Default settings:

```json
{
  "rdflibOntologyAutocomplete.ontologyFiles": [
    "**/*.ttl",
    "**/*.owl",
    "**/*.rdf",
    "**/*.nt",
    "**/*.jsonld"
  ],
  "rdflibOntologyAutocomplete.exclude": [
    "**/.venv/**",
    "**/venv/**",
    "**/node_modules/**",
    "**/.git/**"
  ],
  "rdflibOntologyAutocomplete.enableDiagnostics": false,
  "rdflibOntologyAutocomplete.enableStandardVocabularies": true,
  "rdflibOntologyAutocomplete.pythonPath": "",
  "rdflibOntologyAutocomplete.logLevel": "info"
}
```

Set `rdflibOntologyAutocomplete.pythonPath` to a Python executable or virtual environment directory if you want the extension to use a specific interpreter. The setting supports `${workspaceFolder}`.

Set `rdflibOntologyAutocomplete.enableStandardVocabularies` to `false` if you only want suggestions from ontology files in the workspace.

## Supported Ontology Types

The scanner indexes subjects with these RDF types:

- `owl:Class`
- `rdfs:Class`
- `rdf:Property`
- `owl:ObjectProperty`
- `owl:DatatypeProperty`
- `owl:AnnotationProperty`
