@@ -3,29 +3,29 @@ import {
3
3
CompletionContext ,
4
4
CompletionList ,
5
5
CompletionTriggerKind ,
6
+ MarkupContent ,
7
+ MarkupKind ,
6
8
Position ,
7
9
Range ,
8
10
TextDocumentIdentifier ,
9
11
TextEdit ,
10
- MarkupContent ,
11
- MarkupKind ,
12
12
} from 'vscode-languageserver' ;
13
13
import {
14
14
Document ,
15
15
isInTag ,
16
16
mapCompletionItemToOriginal ,
17
17
mapRangeToOriginal ,
18
- getNodeIfIsInComponentStartTag ,
19
18
} from '../../../lib/documents' ;
20
- import { isNotNullOrUndefined , pathToUrl , getRegExpMatches , flatten } from '../../../utils' ;
19
+ import { flatten , getRegExpMatches , isNotNullOrUndefined , pathToUrl } from '../../../utils' ;
21
20
import { AppCompletionItem , AppCompletionList , CompletionsProvider } from '../../interfaces' ;
22
- import { SvelteSnapshotFragment , SvelteDocumentSnapshot } from '../DocumentSnapshot' ;
21
+ import { SvelteDocumentSnapshot , SvelteSnapshotFragment } from '../DocumentSnapshot' ;
23
22
import { LSAndTSDocResolver } from '../LSAndTSDocResolver' ;
24
23
import {
25
24
convertRange ,
26
25
getCommitCharactersForScriptElement ,
27
26
scriptElementKindToCompletionItemKind ,
28
27
} from '../utils' ;
28
+ import { getComponentAtPosition } from './utils' ;
29
29
30
30
export interface CompletionEntryWithIdentifer extends ts . CompletionEntry , TextDocumentIdentifier {
31
31
position : Position ;
@@ -135,7 +135,14 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
135
135
fragment : SvelteSnapshotFragment ,
136
136
originalPosition : Position ,
137
137
) : AppCompletionItem < CompletionEntryWithIdentifer > [ ] {
138
- const snapshot = this . getComponentAtPosition ( lang , doc , tsDoc , fragment , originalPosition ) ;
138
+ const snapshot = getComponentAtPosition (
139
+ this . lsAndTsDocResovler ,
140
+ lang ,
141
+ doc ,
142
+ tsDoc ,
143
+ fragment ,
144
+ originalPosition ,
145
+ ) ;
139
146
if ( ! snapshot ) {
140
147
return [ ] ;
141
148
}
@@ -148,50 +155,6 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
148
155
} ) ) ;
149
156
}
150
157
151
- /**
152
- * If the completion happens inside the template and within the
153
- * tag of a Svelte component, then retrieve its snapshot.
154
- */
155
- private getComponentAtPosition (
156
- lang : ts . LanguageService ,
157
- doc : Document ,
158
- tsDoc : SvelteDocumentSnapshot ,
159
- fragment : SvelteSnapshotFragment ,
160
- originalPosition : Position ,
161
- ) : SvelteDocumentSnapshot | null {
162
- if ( tsDoc . parserError ) {
163
- return null ;
164
- }
165
-
166
- if (
167
- isInTag ( originalPosition , doc . scriptInfo ) ||
168
- isInTag ( originalPosition , doc . moduleScriptInfo )
169
- ) {
170
- // Inside script tags -> not a component
171
- return null ;
172
- }
173
-
174
- const node = getNodeIfIsInComponentStartTag ( doc . html , doc . offsetAt ( originalPosition ) ) ;
175
- if ( ! node ) {
176
- return null ;
177
- }
178
-
179
- const generatedPosition = fragment . getGeneratedPosition ( doc . positionAt ( node . start + 1 ) ) ;
180
- const def = lang . getDefinitionAtPosition (
181
- tsDoc . filePath ,
182
- fragment . offsetAt ( generatedPosition ) ,
183
- ) ?. [ 0 ] ;
184
- if ( ! def ) {
185
- return null ;
186
- }
187
-
188
- const snapshot = this . lsAndTsDocResovler . getSnapshot ( def . fileName ) ;
189
- if ( ! ( snapshot instanceof SvelteDocumentSnapshot ) ) {
190
- return null ;
191
- }
192
- return snapshot ;
193
- }
194
-
195
158
private toCompletionItem (
196
159
fragment : SvelteSnapshotFragment ,
197
160
comp : ts . CompletionEntry ,
0 commit comments