@@ -955,27 +955,29 @@ describe('server', () => {
955
955
} )
956
956
957
957
describe ( 'onHover' , ( ) => {
958
- it ( 'responds with documentation for command' , async ( ) => {
958
+ async function getHoverResult ( uri : string , position : LSP . Position ) {
959
959
const { connection } = await initializeServer ( )
960
960
961
961
const onHover = connection . onHover . mock . calls [ 0 ] [ 0 ]
962
962
963
- const result = await onHover (
963
+ return onHover (
964
964
{
965
965
textDocument : {
966
- uri : FIXTURE_URI . INSTALL ,
967
- } ,
968
- position : {
969
- // rm
970
- line : 25 ,
971
- character : 5 ,
966
+ uri,
972
967
} ,
968
+ position,
973
969
} ,
974
970
{ } as any ,
975
971
{ } as any ,
976
972
)
973
+ }
974
+ it ( 'responds with documentation for command' , async ( ) => {
975
+ const result = await getHoverResult ( FIXTURE_URI . INSTALL , {
976
+ // rm
977
+ line : 25 ,
978
+ character : 5 ,
979
+ } )
977
980
978
- expect ( result ) . toBeDefined ( )
979
981
expect ( result ) . toEqual ( {
980
982
contents : {
981
983
kind : 'markdown' ,
@@ -985,25 +987,11 @@ describe('server', () => {
985
987
} )
986
988
987
989
it ( 'responds with function documentation extracted from comments' , async ( ) => {
988
- const { connection } = await initializeServer ( )
989
-
990
- const onHover = connection . onHover . mock . calls [ 0 ] [ 0 ]
991
-
992
- const result = await onHover (
993
- {
994
- textDocument : {
995
- uri : FIXTURE_URI . COMMENT_DOC ,
996
- } ,
997
- position : {
998
- line : 17 ,
999
- character : 0 ,
1000
- } ,
1001
- } ,
1002
- { } as any ,
1003
- { } as any ,
1004
- )
990
+ const result = await getHoverResult ( FIXTURE_URI . COMMENT_DOC , {
991
+ line : 17 ,
992
+ character : 0 ,
993
+ } )
1005
994
1006
- expect ( result ) . toBeDefined ( )
1007
995
expect ( result ) . toMatchInlineSnapshot ( `
1008
996
Object {
1009
997
"contents": Object {
@@ -1022,25 +1010,11 @@ describe('server', () => {
1022
1010
} )
1023
1011
1024
1012
it ( 'displays correct documentation for symbols in file that override path executables' , async ( ) => {
1025
- const { connection } = await initializeServer ( )
1026
-
1027
- const onHover = connection . onHover . mock . calls [ 0 ] [ 0 ]
1028
-
1029
- const result = await onHover (
1030
- {
1031
- textDocument : {
1032
- uri : FIXTURE_URI . OVERRIDE_SYMBOL ,
1033
- } ,
1034
- position : {
1035
- line : 9 ,
1036
- character : 1 ,
1037
- } ,
1038
- } ,
1039
- { } as any ,
1040
- { } as any ,
1041
- )
1013
+ const result = await getHoverResult ( FIXTURE_URI . OVERRIDE_SYMBOL , {
1014
+ line : 9 ,
1015
+ character : 1 ,
1016
+ } )
1042
1017
1043
- expect ( result ) . toBeDefined ( )
1044
1018
expect ( result ) . toMatchInlineSnapshot ( `
1045
1019
Object {
1046
1020
"contents": Object {
@@ -1056,28 +1030,22 @@ describe('server', () => {
1056
1030
} )
1057
1031
1058
1032
it ( 'returns executable documentation if the function is not redefined' , async ( ) => {
1059
- const { connection } = await initializeServer ( )
1060
-
1061
- const onHover = connection . onHover . mock . calls [ 0 ] [ 0 ]
1062
-
1063
- const getHoverResult = ( position : LSP . Position ) =>
1064
- onHover (
1065
- {
1066
- textDocument : {
1067
- uri : FIXTURE_URI . OVERRIDE_SYMBOL ,
1068
- } ,
1069
- position,
1070
- } ,
1071
- { } as any ,
1072
- { } as any ,
1073
- )
1074
-
1075
- const result1 = await getHoverResult ( { line : 2 , character : 1 } )
1076
- expect ( result1 ) . toBeDefined ( )
1077
- expect ( ( result1 as any ) ?. contents . value ) . toContain ( 'list directory contents' )
1033
+ const result1 = await getHoverResult ( FIXTURE_URI . OVERRIDE_SYMBOL , {
1034
+ line : 2 ,
1035
+ character : 1 ,
1036
+ } )
1037
+ expect ( result1 ) . toEqual ( {
1038
+ contents : {
1039
+ kind : 'markdown' ,
1040
+ value : expect . stringContaining ( 'list directory contents' ) ,
1041
+ } ,
1042
+ } )
1078
1043
1079
1044
// return null same result if the cursor is on the arguments
1080
- const result2 = await getHoverResult ( { line : 2 , character : 3 } )
1045
+ const result2 = await getHoverResult ( FIXTURE_URI . OVERRIDE_SYMBOL , {
1046
+ line : 2 ,
1047
+ character : 3 ,
1048
+ } )
1081
1049
expect ( result2 ) . toBeDefined ( )
1082
1050
expect ( ( result2 as any ) ?. contents . value ) . toBeUndefined ( )
1083
1051
} )
0 commit comments