@@ -3,6 +3,7 @@ import * as Mocha from 'mocha';
3
3
import * as path from 'path' ;
4
4
import * as vscode from 'vscode' ;
5
5
import * as lc from 'vscode-languageclient' ;
6
+ import type { MarkupContent } from 'vscode-languageclient' ;
6
7
7
8
Mocha . suite ( 'LSP' , ( ) => {
8
9
Mocha . test ( 'textDocument/documentSymbol' , async ( ) => {
@@ -49,4 +50,82 @@ Mocha.suite('LSP', () => {
49
50
assert . deepStrictEqual ( syms [ 0 ] ?. children [ 3 ] . name , 'this_is_a_test' ) ;
50
51
assert . deepStrictEqual ( syms [ 0 ] ?. children [ 3 ] ?. detail , '["test", "expected_failure"]' ) ;
51
52
} ) ;
53
+
54
+ Mocha . test ( 'textDocument/hover for definition in the same module' , async ( ) => {
55
+ const ext = vscode . extensions . getExtension ( 'move.move-analyzer' ) ;
56
+ assert . ok ( ext ) ;
57
+
58
+ await ext . activate ( ) ; // Synchronous waiting for activation to complete
59
+
60
+ // 1. get workdir
61
+ const workDir = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ?? '' ;
62
+
63
+ // 2. open doc
64
+ const docs = await vscode . workspace . openTextDocument (
65
+ path . join ( workDir , 'sources/M2.move' ) ,
66
+ ) ;
67
+ await vscode . window . showTextDocument ( docs ) ;
68
+
69
+ // 3. execute command
70
+ const params : lc . HoverParams = {
71
+ textDocument : {
72
+ uri : docs . uri . toString ( ) ,
73
+ } ,
74
+ position : {
75
+ line : 12 ,
76
+ character : 8 ,
77
+ } ,
78
+ } ;
79
+
80
+ const hoverResult : lc . Hover | undefined =
81
+ await vscode . commands . executeCommand (
82
+ 'move-analyzer.textDocumentHover' ,
83
+ params ,
84
+ ) ;
85
+
86
+ assert . ok ( hoverResult ) ;
87
+ assert . deepStrictEqual ( ( hoverResult . contents as MarkupContent ) . value ,
88
+ // eslint-disable-next-line max-len
89
+ 'fun Symbols::M2::other_doc_struct(): Symbols::M3::OtherDocStruct\n\n\nThis is a multiline docstring\n\nThis docstring has empty lines.\n\nIt uses the ** format instead of ///\n\n' ) ;
90
+
91
+ } ) ;
92
+
93
+ Mocha . test ( 'textDocument/hover for definition in an external module' , async ( ) => {
94
+ const ext = vscode . extensions . getExtension ( 'move.move-analyzer' ) ;
95
+ assert . ok ( ext ) ;
96
+
97
+ await ext . activate ( ) ; // Synchronous waiting for activation to complete
98
+
99
+ // 1. get workdir
100
+ const workDir = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ?? '' ;
101
+
102
+ // 2. open doc
103
+ const docs = await vscode . workspace . openTextDocument (
104
+ path . join ( workDir , 'sources/M2.move' ) ,
105
+ ) ;
106
+ await vscode . window . showTextDocument ( docs ) ;
107
+
108
+ // 3. execute command
109
+ const params : lc . HoverParams = {
110
+ textDocument : {
111
+ uri : docs . uri . toString ( ) ,
112
+ } ,
113
+ position : {
114
+ line : 18 ,
115
+ character : 35 ,
116
+ } ,
117
+ } ;
118
+
119
+ const hoverResult : lc . Hover | undefined =
120
+ await vscode . commands . executeCommand (
121
+ 'move-analyzer.textDocumentHover' ,
122
+ params ,
123
+ ) ;
124
+
125
+
126
+ assert . ok ( hoverResult ) ;
127
+ assert . deepStrictEqual ( ( hoverResult . contents as MarkupContent ) . value ,
128
+ 'Symbols::M3::OtherDocStruct\n\nDocumented struct in another module\n' ) ;
129
+
130
+ } ) ;
52
131
} ) ;
0 commit comments