1
- < < < << << HEAD
2
- import fs from "fs ";
3
- import path from "path ";
4
- import {
5
- === === =
6
1
import type {
7
- >>> >>> > v0 .9 .184 - vscode
8
2
ChunkWithoutID ,
9
3
ContextItem ,
10
4
ContextSubmenuItem ,
11
5
IDE ,
12
6
IndexTag ,
13
7
IndexingProgressUpdate ,
14
- < < << << < HEAD
15
- } from ".." ;
16
- import { getBasename , getLastNPathParts } from "../util/index.js" ;
17
- import {
18
- getLanguageForFile ,
19
- getParserForFile ,
20
- supportedLanguages ,
21
- } from "../util/treeSitter" ;
22
- import { DatabaseConnection , SqliteDb , tagToString } from "./refreshIndex" ;
23
- import {
24
- CodebaseIndex ,
25
- IndexResultType ,
26
- MarkCompleteCallback ,
27
- RefreshIndexResults ,
28
- } from "./types" ;
29
-
30
- export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
31
- === === =
32
8
} from "../index.js" ;
33
9
import { getBasename , getLastNPathParts } from "../util/index.js" ;
34
10
import {
@@ -46,7 +22,6 @@ import {
46
22
47
23
export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
48
24
relativeExpectedTime : number = 1 ;
49
- >>> > >>> v0 .9 .184 - vscode
50
25
artifactId = "codeSnippets" ;
51
26
52
27
constructor ( private readonly ide : IDE ) { }
@@ -70,45 +45,16 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
70
45
)` ) ;
71
46
}
72
47
73
- << << << < HEAD
74
- private getQuerySource ( filepath : string ) {
75
- const fullLangName = supportedLanguages [ filepath . split ( "." ) . pop ( ) ?? "" ] ;
76
- const sourcePath = path . join (
77
- __dirname ,
78
- ".." ,
79
- "tree-sitter" ,
80
- "code-snippet-queries" ,
81
- `tree-sitter-${ fullLangName } -tags.scm` ,
82
- ) ;
83
- if ( ! fs . existsSync ( sourcePath ) ) {
84
- return "" ;
85
- }
86
- return fs . readFileSync ( sourcePath ) . toString ( ) ;
87
- }
88
-
89
- === === =
90
- >>> >>> > v0 .9 .184 - vscode
91
48
async getSnippetsInFile (
92
49
filepath : string ,
93
50
contents : string ,
94
51
) : Promise < ( ChunkWithoutID & { title : string } ) [ ] > {
95
- << < < < << HEAD
96
- const lang = await getLanguageForFile ( filepath ) ;
97
- if ( ! lang ) {
98
- return [ ] ;
99
- }
100
- = === ===
101
- >>> >>> > v0 .9 .184 - vscode
102
52
const parser = await getParserForFile ( filepath ) ;
103
53
if ( ! parser ) {
104
54
return [ ] ;
105
55
}
106
56
const ast = parser . parse ( contents ) ;
107
- < < < << << HEAD
108
- const query = lang ?. query ( this . getQuerySource ( filepath ) ) ;
109
- === = ===
110
57
const query = await getQueryForFile ( filepath , TSQueryType . CodeSnippets ) ;
111
- >>> > >>> v0 .9 .184 - vscode
112
58
const matches = query ?. matches ( ast . rootNode ) ;
113
59
114
60
return (
@@ -138,12 +84,6 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
138
84
139
85
for ( let i = 0 ; i < results . compute . length ; i ++ ) {
140
86
const compute = results . compute [ i ] ;
141
- << < < < << HEAD
142
- const snippets = await this . getSnippetsInFile (
143
- compute . path ,
144
- await this . ide . readFile ( compute . path ) ,
145
- ) ;
146
- === = ===
147
87
148
88
let snippets : ( ChunkWithoutID & { title : string } ) [ ] = [ ] ;
149
89
try {
@@ -154,16 +94,11 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
154
94
} catch ( e ) {
155
95
// If can't parse, assume malformatted code
156
96
}
157
- >>> > >>> v0 .9 .184 - vscode
158
97
159
98
// Add snippets to sqlite
160
99
for ( const snippet of snippets ) {
161
100
const { lastID } = await db . run (
162
- < < < << << HEAD
163
- `INSERT INTO code_snippets (path, cacheKey, content, title, startLine, endLine) VALUES (?, ?, ?, ?, ?, ?)` ,
164
- = === ===
165
101
"INSERT INTO code_snippets (path, cacheKey, content, title, startLine, endLine) VALUES (?, ?, ?, ?, ?, ?)" ,
166
- >>> > >>> v0 .9 .184 - vscode
167
102
[
168
103
compute . path ,
169
104
compute . cacheKey ,
@@ -175,21 +110,13 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
175
110
) ;
176
111
177
112
await db . run (
178
- < < < << << HEAD
179
- `INSERT INTO code_snippets_tags (snippetId, tag) VALUES (?, ?)` ,
180
- = === ===
181
113
"INSERT INTO code_snippets_tags (snippetId, tag) VALUES (?, ?)" ,
182
- > >>> >>> v0 .9 .184 - vscode
183
114
[ lastID , tagString ] ,
184
115
) ;
185
116
}
186
117
187
118
yield {
188
- < << < < < < HEAD
189
- desc : `Indexing ${compute . path } `,
190
- = === ===
191
119
desc : `Indexing ${ getBasename ( compute . path ) } ` ,
192
- > > >>> > > v0 .9 .184 - vscode
193
120
progress : i / results . compute . length ,
194
121
status : "indexing" ,
195
122
} ;
@@ -199,39 +126,24 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
199
126
for ( let i = 0 ; i < results . del . length ; i ++ ) {
200
127
const del = results . del [ i ] ;
201
128
const deleted = await db . run (
202
- << << << < HEAD
203
- `DELETE FROM code_snippets WHERE path = ? AND cacheKey = ?`,
204
- [ del . path , del . cacheKey ] ,
205
- ) ;
206
- await db . run ( `DELETE FROM code_snippets_tags WHERE snippetId = ?`, [
207
- === === =
208
129
"DELETE FROM code_snippets WHERE path = ? AND cacheKey = ?" ,
209
130
[ del . path , del . cacheKey ] ,
210
131
) ;
211
132
await db . run ( "DELETE FROM code_snippets_tags WHERE snippetId = ?" , [
212
- >>> >>> > v0 .9 .184 - vscode
213
133
deleted . lastID ,
214
134
] ) ;
215
135
markComplete ( [ del ] , IndexResultType . Delete ) ;
216
136
}
217
137
218
138
for ( let i = 0 ; i < results . addTag . length ; i ++ ) {
219
139
const snippetsWithPath = await db . all (
220
- << << << < HEAD
221
- `SELECT * FROM code_snippets WHERE cacheKey = ?`,
222
- === === =
223
140
"SELECT * FROM code_snippets WHERE cacheKey = ?" ,
224
- >>> >>> > v0 .9 .184 - vscode
225
141
[ results . addTag [ i ] . cacheKey ] ,
226
142
) ;
227
143
228
144
for ( const snippet of snippetsWithPath ) {
229
145
await db . run (
230
- << << << < HEAD
231
- `INSERT INTO code_snippets_tags ( snippetId , tag ) VALUES ( ?, ?) `,
232
- === === =
233
146
"INSERT INTO code_snippets_tags (snippetId, tag) VALUES (?, ?)" ,
234
- >>> >>> > v0 .9 .184 - vscode
235
147
[ snippet . id , tagString ] ,
236
148
) ;
237
149
}
@@ -258,11 +170,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
258
170
259
171
static async getForId ( id : number ) : Promise < ContextItem > {
260
172
const db = await SqliteDb . get ( ) ;
261
- << < < < << HEAD
262
- const row = await db . get ( `SELECT * FROM code_snippets WHERE id = ?` , [ id ] ) ;
263
- === = ===
264
173
const row = await db . get ( "SELECT * FROM code_snippets WHERE id = ?" , [ id ] ) ;
265
- >>> > >>> v0 .9 .184 - vscode
266
174
267
175
return {
268
176
name : row . title ,
0 commit comments