@@ -10,6 +10,7 @@ import {
1010 createDocumentHighlightProvider ,
1111 createHoverProvider ,
1212 createReferencesProvider ,
13+ clearReferenceResultCache ,
1314} from './providers'
1415import { API } from './util/api'
1516
@@ -85,7 +86,7 @@ describe('createDefinitionProvider', () => {
8586 assert . deepStrictEqual ( await gatherValues ( result ) , [ location1 , location2 ] )
8687 } )
8788
88- it ( 'falls back to basic when precise results are not found' , async ( ) => {
89+ it ( 'falls back to search when precise results are not found' , async ( ) => {
8990 const result = createDefinitionProvider (
9091 ( ) => Promise . resolve ( null ) ,
9192 ( ) => asyncGeneratorFromValues ( [ location3 ] ) ,
@@ -107,6 +108,8 @@ describe('createDefinitionProvider', () => {
107108} )
108109
109110describe ( 'createReferencesProvider' , ( ) => {
111+ beforeEach ( clearReferenceResultCache )
112+
110113 it ( 'uses LSIF definitions as source of truth' , async ( ) => {
111114 const result = createReferencesProvider (
112115 ( ) =>
@@ -205,7 +208,8 @@ describe('createReferencesProvider', () => {
205208 undefined ,
206209 undefined ,
207210 undefined ,
208- makeStubAPI ( )
211+ makeStubAPI ( ) ,
212+ ( ) => true
209213 ) . provideReferences ( textDocument , position , {
210214 includeDeclaration : false ,
211215 } ) as Observable < sourcegraph . Badged < sourcegraph . Location > [ ] >
@@ -244,7 +248,63 @@ describe('createReferencesProvider', () => {
244248 undefined ,
245249 undefined ,
246250 undefined ,
247- makeStubAPI ( )
251+ makeStubAPI ( ) ,
252+ ( ) => true
253+ ) . provideReferences ( textDocument , position , {
254+ includeDeclaration : false ,
255+ } ) as Observable < sourcegraph . Badged < sourcegraph . Location > [ ] >
256+
257+ assert . deepStrictEqual ( await gatherValues ( result ) , [
258+ [
259+ { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
260+ { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
261+ ] ,
262+ [
263+ { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
264+ { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
265+ { ...location3 , aggregableBadges : [ indicators . semanticBadge ] } ,
266+ ] ,
267+ [
268+ { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
269+ { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
270+ { ...location3 , aggregableBadges : [ indicators . semanticBadge ] } ,
271+ {
272+ ...location4 ,
273+ badge : indicators . impreciseBadge ,
274+ aggregableBadges : [ indicators . searchBasedBadge ] ,
275+ } ,
276+ ] ,
277+ [
278+ { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
279+ { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
280+ { ...location3 , aggregableBadges : [ indicators . semanticBadge ] } ,
281+ {
282+ ...location4 ,
283+ badge : indicators . impreciseBadge ,
284+ aggregableBadges : [ indicators . searchBasedBadge ] ,
285+ } ,
286+ {
287+ ...location9 ,
288+ badge : indicators . impreciseBadge ,
289+ aggregableBadges : [ indicators . searchBasedBadge ] ,
290+ } ,
291+ ] ,
292+ ] )
293+ } )
294+
295+ it ( 'supplements LSIF results with search results (disabled)' , async ( ) => {
296+ const result = createReferencesProvider (
297+ ( ) =>
298+ asyncGeneratorFromValues ( [
299+ [ location1 , location2 ] ,
300+ [ location1 , location2 , location3 ] ,
301+ ] ) ,
302+ ( ) => asyncGeneratorFromValues ( [ [ location4 ] , [ location4 , location7 , location8 , location9 ] ] ) ,
303+ undefined ,
304+ undefined ,
305+ undefined ,
306+ makeStubAPI ( ) ,
307+ ( ) => false
248308 ) . provideReferences ( textDocument , position , {
249309 includeDeclaration : false ,
250310 } ) as Observable < sourcegraph . Badged < sourcegraph . Location > [ ] >
@@ -259,6 +319,36 @@ describe('createReferencesProvider', () => {
259319 { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
260320 { ...location3 , aggregableBadges : [ indicators . semanticBadge ] } ,
261321 ] ,
322+ ] )
323+ } )
324+
325+ it ( 'supplements LSIF results with search results (toggled)' , async ( ) => {
326+ const mixedResults = createReferencesProvider (
327+ ( ) =>
328+ asyncGeneratorFromValues ( [
329+ [ location1 , location2 ] ,
330+ [ location1 , location2 , location3 ] ,
331+ ] ) ,
332+ ( ) => asyncGeneratorFromValues ( [ [ location4 ] , [ location4 , location7 , location8 , location9 ] ] ) ,
333+ undefined ,
334+ undefined ,
335+ undefined ,
336+ makeStubAPI ( ) ,
337+ ( ) => true
338+ ) . provideReferences ( textDocument , position , {
339+ includeDeclaration : false ,
340+ } ) as Observable < sourcegraph . Badged < sourcegraph . Location > [ ] >
341+
342+ assert . deepStrictEqual ( await gatherValues ( mixedResults ) , [
343+ [
344+ { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
345+ { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
346+ ] ,
347+ [
348+ { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
349+ { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
350+ { ...location3 , aggregableBadges : [ indicators . semanticBadge ] } ,
351+ ] ,
262352 [
263353 { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
264354 { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
@@ -285,6 +375,31 @@ describe('createReferencesProvider', () => {
285375 } ,
286376 ] ,
287377 ] )
378+
379+ const preciseResults = createReferencesProvider (
380+ ( ) =>
381+ asyncGeneratorFromValues ( [
382+ [ location1 , location2 ] ,
383+ [ location1 , location2 , location3 ] ,
384+ ] ) ,
385+ ( ) => asyncGeneratorFromValues ( [ [ location4 ] , [ location4 , location7 , location8 , location9 ] ] ) ,
386+ undefined ,
387+ undefined ,
388+ undefined ,
389+ makeStubAPI ( ) ,
390+ ( ) => false
391+ ) . provideReferences ( textDocument , position , {
392+ includeDeclaration : false ,
393+ } ) as Observable < sourcegraph . Badged < sourcegraph . Location > [ ] >
394+
395+ // Should immediately return all precise results from previous call
396+ assert . deepStrictEqual ( await gatherValues ( preciseResults ) , [
397+ [
398+ { ...location1 , aggregableBadges : [ indicators . semanticBadge ] } ,
399+ { ...location2 , aggregableBadges : [ indicators . semanticBadge ] } ,
400+ { ...location3 , aggregableBadges : [ indicators . semanticBadge ] } ,
401+ ] ,
402+ ] )
288403 } )
289404} )
290405
@@ -383,7 +498,7 @@ describe('createHoverProvider', () => {
383498 ] )
384499 } )
385500
386- it ( 'falls back to basic when precise results are not found' , async ( ) => {
501+ it ( 'falls back to search when precise results are not found' , async ( ) => {
387502 const result = createHoverProvider (
388503 LSIFSupport . None ,
389504 ( ) => Promise . resolve ( null ) ,
0 commit comments