@@ -90,6 +90,32 @@ const SAGEMATH_METHODS = [
9090 'save' , 'load' , 'show' , 'latex' , 'pretty_print'
9191] ;
9292
93+ const SYMBOL_DOCUMENTATION : Record < string , string > = {
94+ ZZ : 'The ring of integers. Example: `ZZ(5)` creates the integer 5 in the integer ring.' ,
95+ QQ : 'The field of rational numbers. Example: `QQ(1/2)` creates the rational number 1/2.' ,
96+ RR : 'The field of real numbers with arbitrary precision. Example: `RR(pi)`.' ,
97+ CC : 'The field of complex numbers. Example: `CC(1, 2)` creates `1 + 2*I`.' ,
98+ PolynomialRing : 'Creates a polynomial ring. Example: `R = PolynomialRing(QQ, "x"); x = R.gen()`.' ,
99+ LaurentPolynomialRing : 'Creates a Laurent polynomial ring. Example: `R = LaurentPolynomialRing(QQ, "x")`.' ,
100+ PowerSeriesRing : 'Creates a power series ring. Example: `R = PowerSeriesRing(QQ, "x")`.' ,
101+ NumberField : 'Creates a number field. Example: `K = NumberField(x^2 - 2, "a")`.' ,
102+ GF : 'Creates a finite field (Galois field). Example: `F = GF(7)` 或 `F = GF(2^8)`.' ,
103+ EllipticCurve : 'Creates an elliptic curve. Example: `EllipticCurve([0, 0, 0, -1, 0])`.' ,
104+ var : 'Creates symbolic variables. Example: `var("x y z")` creates symbolic variables x, y, z.' ,
105+ matrix : 'Creates a matrix. Example: `matrix([[1, 2], [3, 4]])` creates a 2×2 matrix.' ,
106+ plot : 'Plots functions. Example: `plot(sin(x), (x, 0, 2*pi))`.' ,
107+ solve : 'Solves equations. Example: `solve(x^2 - 4 == 0, x)`.' ,
108+ factor : 'Factors polynomials or integers. Example: `factor(x^2 - 4)`.' ,
109+ integrate : 'Computes integrals. Example: `integrate(sin(x), x)`.' ,
110+ diff : 'Computes derivatives. Example: `diff(sin(x), x)`.' ,
111+ expand : 'Expands expressions. Example: `expand((x + 1)^3)`.' ,
112+ simplify : 'Simplifies expressions. Example: `simplify(sin(x)^2 + cos(x)^2)`.' ,
113+ Graph : 'Creates a graph. Example: `G = Graph(); G.add_edges([(1, 2), (2, 3)])`.' ,
114+ gcd : 'Greatest common divisor. Example: `gcd(12, 18)`.' ,
115+ is_prime : 'Primality test. Example: `is_prime(17)`.' ,
116+ factorial : 'Computes factorial. Example: `factorial(5)`.'
117+ } ;
118+
93119connection . onInitialize ( ( params : InitializeParams ) => {
94120 const capabilities = params . capabilities ;
95121
@@ -444,19 +470,26 @@ connection.onCompletionResolve(
444470
445471// Provide hover information
446472connection . onHover (
447- ( _textDocumentPosition : TextDocumentPositionParams ) : Hover | undefined => {
448- // This is a simplified hover provider
449- // In a real implementation, you'd parse the document to find what's under the cursor
473+ ( textDocumentPosition : TextDocumentPositionParams ) : Hover | undefined => {
474+ const document = documents . get ( textDocumentPosition . textDocument . uri ) ;
475+ if ( ! document ) {
476+ return undefined ;
477+ }
478+
479+ const word = getWordAtPosition ( document , textDocumentPosition . position ) ;
480+ if ( ! word ) {
481+ return undefined ;
482+ }
483+
484+ const doc = SYMBOL_DOCUMENTATION [ word ] ;
485+ if ( ! doc ) {
486+ return undefined ;
487+ }
488+
450489 return {
451490 contents : {
452491 kind : MarkupKind . Markdown ,
453- value : [
454- '**SageMath Enhanced**' ,
455- '' ,
456- 'Hover over SageMath symbols to get documentation.' ,
457- '' ,
458- 'Use Ctrl+Space for code completion.'
459- ] . join ( '\n' )
492+ value : `**${ word } **\n\n${ doc } `
460493 }
461494 } ;
462495 }
0 commit comments