Skip to content

Commit ecc7bab

Browse files
committed
doc: update examples
1 parent 12038fb commit ecc7bab

File tree

2 files changed

+48
-123
lines changed

2 files changed

+48
-123
lines changed

README.md

Lines changed: 37 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,29 @@ sequenceDiagram
4545
LSAP-->>Agent: 2. Structured Markdown (Callers + Code Context)
4646
```
4747

48+
## Protocol Specification
49+
50+
LSAP is a formally defined protocol with complete **JSON Schema** specifications for all interaction models. The [`schema/`](schema/) directory contains:
51+
52+
- **Request/Response Schemas**: Each capability (e.g., `definition`, `outline`, `rename`, etc.) has dedicated request and response schemas.
53+
- **Field Definitions**: Precise specifications of input parameters, output fields, and data types.
54+
- **Rendering Templates**: Standardized Markdown templates for formatting responses, ensuring consistent agent-facing outputs.
55+
56+
This formal specification ensures:
57+
58+
- **Type Safety**: Strong contracts between agents and LSAP implementations.
59+
- **Interoperability**: Different LSAP implementations can be swapped without breaking agent workflows.
60+
- **Extensibility**: New capabilities can be added following the established schema patterns.
61+
62+
Example schema files: `definition.request.json`, `definition.response.json`, `reference.request.json`, `reference.response.json`, etc.
63+
4864
## Interaction Examples
4965

5066
LSAP's interaction design strictly follows the **Markdown-First** principle: input expresses intent, and output provides refined knowledge.
5167

5268
### 1. Find References
5369

54-
**Request:**
70+
**Request (using symbol path):**
5571

5672
```json
5773
{
@@ -64,6 +80,19 @@ LSAP's interaction design strictly follows the **Markdown-First** principle: inp
6480
}
6581
```
6682

83+
**Alternative: Request (using find pattern):**
84+
85+
```json
86+
{
87+
"locate": {
88+
"file_path": "src/models.py",
89+
"find": "def validate<|>("
90+
},
91+
"mode": "references",
92+
"max_items": 2
93+
}
94+
```
95+
6796
**Response:**
6897

6998
````markdown
@@ -76,16 +105,19 @@ Total references: 12 | Showing: 2
76105
In `LoginHandler.authenticate` (`method`)
77106

78107
```python
79-
if not User.validate(credentials):
80-
raise AuthError()
108+
44 | def authenticate(credentials):
109+
45 | if not User.validate(credentials):
110+
46 | raise AuthError()
81111
```
82112

83113
### src/api/register.py:28
84114

85115
In `register_user` (`function`)
86116

87117
```python
88-
User.validate(new_user_data)
118+
27 | def register_user(new_user_data):
119+
28 | User.validate(new_user_data)
120+
29 | db.save(new_user_data)
89121
```
90122
````
91123

@@ -208,127 +240,11 @@ Summary: Modified 3 files with 8 occurrences.
208240
> You must manually rename the symbol in the excluded files to maintain consistency.
209241
```
210242

211-
### 2. File Outline
212-
213-
**Request:**
214-
215-
```json
216-
{
217-
"file_path": "src/lsap/capability/rename.py",
218-
"mode": "outline"
219-
}
220-
```
221-
222-
**Response:**
223-
224-
````markdown
225-
# Outline for `src/lsap/capability/rename.py`
226-
227-
## CachedRename (`class`)
228-
229-
## \_get_old_name (`function`)
230-
231-
```python
232-
def _get_old_name(
233-
reader: DocumentReader,
234-
pos: Position,
235-
res: PrepareRenameResult
236-
) -> str
237-
```
238-
239-
## \_matches_exclude_patterns (`function`)
240-
241-
```python
242-
def _matches_exclude_patterns(
243-
path: Path,
244-
patterns: Sequence[str],
245-
workspace_root: Path
246-
) -> bool
247-
```
248-
249-
---
250-
251-
Check if path matches any of the exclude patterns.
252-
````
253-
254-
### 3. Safe Rename (Two-Step Workflow)
255-
256-
**Request (Preview):**
257-
258-
```json
259-
{
260-
"locate": {
261-
"file_path": "src/lsap/schema/rename.py",
262-
"locate": "RenameDiff"
263-
},
264-
"new_name": "LineChange",
265-
"mode": "rename_preview"
266-
}
267-
```
268-
269-
**Response:**
270-
271-
````markdown
272-
# Rename Preview: `RenameDiff``LineChange`
273-
274-
ID: `045d72`
275-
Summary: Affects 2 files and 7 occurrences.
276-
277-
## `src/lsap/schema/rename.py`
278-
279-
Line 10:
280-
281-
```diff
282-
- class RenameDiff(BaseModel):
283-
+ class LineChange(BaseModel):
284-
```
285-
286-
Line 22:
287-
288-
```diff
289-
- diffs: list[RenameDiff]
290-
+ diffs: list[LineChange]
291-
```
292-
293-
---
294-
295-
> [!TIP]
296-
> To apply this rename, use `rename_execute` with `rename_id="045d72"`.
297-
````
298-
299-
**Request (Execute):**
300-
301-
```json
302-
{
303-
"rename_id": "045d72",
304-
"exclude_files": ["tests/**/*.py"],
305-
"mode": "rename_execute"
306-
}
307-
```
308-
309-
**Response:**
310-
311-
```markdown
312-
# Rename Applied: `RenameDiff``LineChange`
313-
314-
Summary: Modified 2 files with 7 occurrences.
315-
316-
- `src/lsap/schema/rename.py`: 2 occurrences
317-
- `src/lsap/capability/rename.py`: 5 occurrences
318-
319-
---
320-
321-
> [!NOTE]
322-
> Rename completed successfully. Excluded files: `tests/**/*.py`.
323-
> [!IMPORTANT]
324-
> You must manually rename the symbol in the excluded files to maintain consistency.
325-
```
326-
327243
## I'm Not Convinced...
328244

329245
### "LSAP Just Replicates LSP—What's Special?"
330246

331-
While LSP provides **atomic operations**, LSAP offers **composed capabilities**.
247+
While LSP provides **atomic operations**, LSAP offers **composed capabilities** that brings more powerful functionalities.
332248

333249
For instance, the **[Relation API](docs/schemas/draft/relation.md)** (still in draft, but soon will be released) finds call paths between functions in a single request (handling traversal, cycles, and formatting), a task requiring complex orchestration in raw LSP.
334250

docs/locate_design.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,23 @@ Token boundaries align with programming language semantics. It preserves identif
189189
### 1. Find All References of a Symbol
190190
191191
```python
192-
# Locate the declaration of class MyClass
192+
# Option 1: Using SymbolScope
193193
Locate(
194194
file_path="models.py",
195195
scope=SymbolScope(symbol_path=["MyClass"])
196196
)
197+
198+
# Option 2: Using find pattern
199+
Locate(
200+
file_path="models.py",
201+
find="class <|>MyClass"
202+
)
203+
204+
# Or using string syntax:
205+
parse_locate_string("models.py@class <|>MyClass")
197206
```
198207

199-
The resolver treats `SymbolScope` as the declaration position of the class name `MyClass` in the source code, suitable for `references`, `rename`, etc.
208+
The resolver treats `SymbolScope` as the declaration position of the class name `MyClass` in the source code. Alternatively, using `find` with a pattern like `"class <|>MyClass"` locates the same position through text matching. Both approaches are suitable for `references`, `rename`, etc.
200209

201210
### 2. Get Hover Information for a Variable
202211

0 commit comments

Comments
 (0)