|
1 | 1 | import { Server } from '@aws/language-server-runtimes/server-interface'
|
2 | 2 | import { TestFeatures } from '@aws/language-server-runtimes/testing'
|
3 | 3 | import { TextDocument } from 'vscode-languageserver-textdocument'
|
4 |
| -import { TextDocumentItem, Hover, SignatureHelp } from 'vscode-languageserver-types' |
| 4 | +import { TextDocumentItem, Hover, SignatureHelp, CompletionList } from 'vscode-languageserver-types' |
5 | 5 | import { PartiQLServerFactory } from './language-server'
|
6 | 6 | import { createPartiQLLanguageService } from './language-service'
|
7 | 7 | import { CancellationTokenSource } from 'vscode-languageserver'
|
@@ -268,3 +268,70 @@ describe('PartiQL Server - SignatureHelp Functionality', () => {
|
268 | 268 | expect(result).toBeNull()
|
269 | 269 | })
|
270 | 270 | })
|
| 271 | + |
| 272 | +describe('PartiQL Server - Completion Functionality', () => { |
| 273 | + let service: ReturnType<typeof createPartiQLLanguageService> |
| 274 | + let server: Server |
| 275 | + let features: TestFeatures |
| 276 | + let completionSpy: jest.SpyInstance |
| 277 | + |
| 278 | + const testContent = `SELECT * FR'` |
| 279 | + const testDocument = TextDocument.create('file:///completionTest.partiql', 'partiql', 1, testContent) |
| 280 | + |
| 281 | + beforeEach(async () => { |
| 282 | + service = createPartiQLLanguageService() |
| 283 | + server = PartiQLServerFactory(service) |
| 284 | + features = new TestFeatures() |
| 285 | + |
| 286 | + await features.start(server) |
| 287 | + features.openDocument(testDocument) |
| 288 | + |
| 289 | + completionSpy = jest.spyOn(service, 'doComplete').mockImplementation((doc, position) => { |
| 290 | + if (position.line === 0 && position.character === 11) { |
| 291 | + return CompletionList.create([{ label: 'FROM' }], false) |
| 292 | + } |
| 293 | + return CompletionList.create([], false) // Return an empty list for other positions |
| 294 | + }) |
| 295 | + }) |
| 296 | + |
| 297 | + afterEach(() => { |
| 298 | + jest.clearAllMocks() |
| 299 | + features.dispose() |
| 300 | + }) |
| 301 | + |
| 302 | + it('should provide correct completions within FROM clause', async () => { |
| 303 | + const completionParams = { |
| 304 | + textDocument: testDocument, |
| 305 | + position: { line: 0, character: 11 }, |
| 306 | + } |
| 307 | + const cancellationToken = new CancellationTokenSource().token |
| 308 | + |
| 309 | + const result = await features.doCompletion(completionParams, cancellationToken) |
| 310 | + |
| 311 | + expect(completionSpy).toHaveBeenCalledWith(testDocument, { line: 0, character: 11 }) |
| 312 | + expect(result).toEqual( |
| 313 | + expect.objectContaining({ |
| 314 | + items: [expect.objectContaining({ label: 'FROM' })], |
| 315 | + isIncomplete: false, |
| 316 | + }) |
| 317 | + ) |
| 318 | + }) |
| 319 | + |
| 320 | + it('should not provide completions outside FROM clause', async () => { |
| 321 | + const completionParams = { |
| 322 | + textDocument: testDocument, |
| 323 | + position: { line: 0, character: 3 }, // Position outside the 'LIKE' clause |
| 324 | + } |
| 325 | + const cancellationToken = new CancellationTokenSource().token |
| 326 | + |
| 327 | + const result = await features.doCompletion(completionParams, cancellationToken) |
| 328 | + |
| 329 | + expect(completionSpy).toHaveBeenCalledWith(testDocument, { line: 0, character: 3 }) |
| 330 | + expect(result).toEqual( |
| 331 | + expect.objectContaining({ |
| 332 | + items: [], |
| 333 | + isIncomplete: false, |
| 334 | + }) |
| 335 | + ) |
| 336 | + }) |
| 337 | +}) |
0 commit comments