1+ #!/usr/bin/env node
2+
3+ const { LSPClient } = require ( './test_lsp_completion.js' ) ;
4+
5+ /**
6+ * Test LLL completion functionality
7+ */
8+ async function testLLLCompletion ( ) {
9+ const client = new LSPClient ( ) ;
10+
11+ try {
12+ // Start server and initialize
13+ await client . startServer ( ) ;
14+ await client . initialize ( ) ;
15+
16+ // Test document content with LLL completion scenarios
17+ const testContent = `# SageMath LLL completion test
18+ # Test case 1: Simple completion
19+ LLL
20+ # Test case 2: Assignment
21+ alg = LLL
22+ # Test case 3: Lowercase partial
23+ lll
24+ # Test case 4: In function call
25+ my_function(LLL
26+ # Test case 5: Just 'L'
27+ L
28+ ` ;
29+
30+ const testUri = 'file:///tests/test_lll_completion.sage' ;
31+ await client . openDocument ( testUri , testContent ) ;
32+
33+ // Wait a bit for document processing
34+ await new Promise ( resolve => setTimeout ( resolve , 500 ) ) ;
35+
36+ console . log ( '\n🧪 Testing LLL completion scenarios...\n' ) ;
37+
38+ // Test cases with expected positions
39+ const testCases = [
40+ { name : 'LLL' , line : 2 , character : 3 , input : 'LLL' } ,
41+ { name : 'LLL' , line : 4 , character : 9 , input : 'LLL' } ,
42+ { name : 'lll' , line : 6 , character : 3 , input : 'lll' } ,
43+ { name : 'LLL' , line : 8 , character : 16 , input : 'LLL' } ,
44+ { name : 'L' , line : 10 , character : 1 , input : 'L' }
45+ ] ;
46+
47+ let allTestsPassed = true ;
48+
49+ for ( const testCase of testCases ) {
50+ console . log ( `📝 Testing "${ testCase . input } " completion...` ) ;
51+
52+ try {
53+ const completions = await client . getCompletion ( testUri , testCase . line , testCase . character ) ;
54+
55+ console . log ( ` Found ${ completions . length } completion items` ) ;
56+
57+ // Check if LLL is in the results
58+ const lllItem = completions . find ( item =>
59+ item . label === 'LLL' ||
60+ item . insertText === 'LLL'
61+ ) ;
62+
63+ if ( lllItem ) {
64+ console . log ( ` ✅ LLL found at position ${ completions . indexOf ( lllItem ) + 1 } ` ) ;
65+ console . log ( ` Sort text: "${ lllItem . sortText } "` ) ;
66+ console . log ( ` Detail: "${ lllItem . detail } "` ) ;
67+
68+ // Check if it's in top 10 (indicating good prioritization)
69+ const position = completions . indexOf ( lllItem ) + 1 ;
70+ if ( position <= 10 ) {
71+ console . log ( ` 🌟 Great! LLL is in top 10 (position ${ position } )` ) ;
72+ } else {
73+ console . log ( ` ⚠️ LLL found but not in top 10 (position ${ position } )` ) ;
74+ }
75+ } else {
76+ console . log ( ` ❌ LLL not found in completion results` ) ;
77+ allTestsPassed = false ;
78+ }
79+
80+ // Show top 5 for debugging
81+ console . log ( ` Top 5 completions:` ) ;
82+ completions . slice ( 0 , 5 ) . forEach ( ( item , index ) => {
83+ console . log ( ` ${ index + 1 } . ${ item . label } (${ item . sortText } )` ) ;
84+ } ) ;
85+
86+ } catch ( error ) {
87+ console . error ( ` 💥 Error testing "${ testCase . input } ":` , error . message ) ;
88+ allTestsPassed = false ;
89+ }
90+
91+ console . log ( '' ) ;
92+ }
93+
94+ console . log ( '📊 Test Summary:' ) ;
95+ if ( allTestsPassed ) {
96+ console . log ( '🎉 All tests passed! LLL completion is working correctly.' ) ;
97+ } else {
98+ console . log ( '❌ Some tests failed! LLL completion needs to be fixed.' ) ;
99+ process . exit ( 1 ) ;
100+ }
101+
102+ } catch ( error ) {
103+ console . error ( '💥 Fatal error:' , error ) ;
104+ process . exit ( 1 ) ;
105+ } finally {
106+ await client . shutdown ( ) ;
107+ }
108+ }
109+
110+ /**
111+ * Main execution
112+ */
113+ async function main ( ) {
114+ console . log ( '🧪 SageMath Enhanced - LLL Completion Test' ) ;
115+ console . log ( '==========================================\n' ) ;
116+
117+ console . log ( 'This script tests the Language Server Protocol completion functionality for LLL.' ) ;
118+ console . log ( 'It verifies that typing "LLL", "lll", "L", etc. returns "LLL" in completion results.\n' ) ;
119+
120+ try {
121+ await testLLLCompletion ( ) ;
122+ } catch ( error ) {
123+ console . error ( '💥 Fatal error:' , error ) ;
124+ process . exit ( 1 ) ;
125+ }
126+ }
127+
128+ // Run the test
129+ if ( require . main === module ) {
130+ main ( ) ;
131+ }
132+
133+ module . exports = { testLLLCompletion } ;
0 commit comments