Skip to content

Commit f4ed038

Browse files
committed
Fix snippet reference handling and improve line extraction logic in llms.txt and generate_llms.py
1 parent ecc2fd4 commit f4ed038

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

llms.txt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36953,7 +36953,7 @@ This component handles connecting to the wallet, switching networks if necessary
3695336953
To integrate this component to your dApp, you need to overwrite the existing boilerplate in `app/page.js` with the following code:
3695436954

3695536955
```javascript title="app/page.js"
36956-
Invalid snippet reference: https://raw.githubusercontent.com/polkadot-developers/polkavm-storage-contract-dapps/refs/tags/v0.0.2/ethers-dapp/app/page.js::1
36956+
'use client';
3695736957
import { useState } from 'react';
3695836958

3695936959
import WalletConnect from './components/WalletConnect';
@@ -37055,7 +37055,7 @@ This component reads the `storedNumber` value from the contract and displays it
3705537055
To see this change in your dApp, you need to integrate this component into the `app/page.js` file:
3705637056

3705737057
```javascript title="app/page.js"
37058-
Invalid snippet reference: https://raw.githubusercontent.com/polkadot-developers/polkavm-storage-contract-dapps/refs/tags/v0.0.2/ethers-dapp/app/page.js::1
37058+
'use client';
3705937059
import { useState } from 'react';
3706037060

3706137061
import WalletConnect from './components/WalletConnect';
@@ -37640,7 +37640,7 @@ This component handles connecting to the wallet, switching networks if necessary
3764037640
To use this component in your dApp, replace the existing boilerplate in `app/page.tsx` with the following code:
3764137641

3764237642
```typescript title="page.tsx"
37643-
Invalid snippet reference: https://raw.githubusercontent.com/polkadot-developers/polkavm-storage-contract-dapps/refs/tags/v0.0.2/viem-dapp/app/page.tsx::1
37643+
"use client";
3764437644
import { useState } from "react";
3764537645
import WalletConnect from "./components/WalletConnect";
3764637646
export default function Home() {
@@ -37747,7 +37747,7 @@ This component reads the `storedNumber` value from the contract and displays it
3774737747
To reflect this change in your dApp, incorporate this component into the `app/page.tsx` file.
3774837748

3774937749
```typescript title="page.tsx"
37750-
Invalid snippet reference: https://raw.githubusercontent.com/polkadot-developers/polkavm-storage-contract-dapps/refs/tags/v0.0.2/viem-dapp/app/page.tsx::1
37750+
"use client";
3775137751
import { useState } from "react";
3775237752
import WalletConnect from "./components/WalletConnect";
3775337753
import ReadContract from "./components/ReadContract";
@@ -38298,7 +38298,25 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
3829838298
1. Create a folder for testing called `test`. Inside that directory, create a file named `Storage.js` and add the following code:
3829938299

3830038300
```javascript title="Storage.js"
38301-
38301+
const { expect } = require('chai');
38302+
const { ethers } = require('hardhat');
38303+
38304+
describe('Storage', function () {
38305+
let storage;
38306+
let owner;
38307+
let addr1;
38308+
38309+
beforeEach(async function () {
38310+
// Get signers
38311+
[owner, addr1] = await ethers.getSigners();
38312+
38313+
// Deploy the Storage contract
38314+
const Storage = await ethers.getContractFactory('Storage');
38315+
storage = await Storage.deploy();
38316+
await storage.waitForDeployment();
38317+
});
38318+
38319+
describe('Basic functionality', function () {
3830238320
// Add your logic here
3830338321
});
3830438322
});

scripts/generate_llms.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,22 @@ def fetch_local_snippet(snippet_ref, snippet_directory):
117117
return snippet_content.strip()
118118

119119
def fetch_remote_snippet(snippet_ref, yaml_data, max_retries=3, backoff_factor=2):
120-
# Match URL with optional line range (start:end)
121-
match = re.match(r'^(https?://[^:]+)(?::(\d+))?(?::(\d+))?$', snippet_ref)
120+
# Match URL with optional line range. Cases:
121+
# - http://example.com:1:3 (this means extract lines 1 to 3)
122+
# - http://example.com::1 (this means extract until line 1)
123+
# - http://example.com (no line range specified, fetch entire content)
124+
match = re.match(r'^(https?://[^\s:]+)(?::(\d*))?(?::(\d*))?$', snippet_ref)
122125

123126
if not match:
124127
print(f"Invalid snippet reference format: {snippet_ref}")
125128
return f"Invalid snippet reference: {snippet_ref}"
126129

127130
url = match.group(1)
128-
line_start = int(match.group(2)) if match.group(2) else None
129-
line_end = int(match.group(3)) if match.group(3) else None
131+
line_start = match.group(2)
132+
line_end = match.group(3)
133+
134+
line_start = int(line_start) if line_start and line_start.isdigit() else None
135+
line_end = int(line_end) if line_end and line_end.isdigit() else None
130136

131137
# Resolve any template placeholders using the yaml_data
132138
url = resolve_placeholders(url, yaml_data)
@@ -148,9 +154,12 @@ def fetch_remote_snippet(snippet_ref, yaml_data, max_retries=3, backoff_factor=2
148154
snippet_content = response.text
149155

150156
# Extract specific lines if requested
151-
if line_start is not None and line_end is not None:
157+
if line_start is not None or line_end is not None:
152158
lines = snippet_content.split('\n')
153-
snippet_content = '\n'.join(lines[line_start - 1:line_end])
159+
# Python slice: start is inclusive, end is exclusive
160+
start = (line_start - 1) if line_start else 0
161+
end = line_end if line_end else len(lines)
162+
snippet_content = '\n'.join(lines[start:end])
154163

155164
return snippet_content.strip()
156165

0 commit comments

Comments
 (0)