@@ -13,71 +13,80 @@ import * as serverUtils from '../omnisharpUtils';
1313
1414class OmniSharpCodeLens extends CodeLens {
1515
16- fileName : string ;
16+ fileName : string ;
1717
18- constructor ( fileName : string , range : Range ) {
19- super ( range ) ;
20- this . fileName = fileName ;
21- }
18+ constructor ( fileName : string , range : Range ) {
19+ super ( range ) ;
20+ this . fileName = fileName ;
21+ }
2222}
2323
2424export default class OmniSharpCodeLensProvider extends AbstractSupport implements CodeLensProvider {
2525
26- private static filteredSymbolNames : { [ name : string ] : boolean } = {
27- 'Equals' : true ,
28- 'Finalize' : true ,
29- 'GetHashCode' : true ,
30- 'ToString' : true
31- } ;
32-
33- provideCodeLenses ( document : TextDocument , token : CancellationToken ) : CodeLens [ ] | Thenable < CodeLens [ ] > {
34-
35- return serverUtils . currentFileMembersAsTree ( this . _server , { Filename : document . fileName } , token ) . then ( tree => {
36- let ret : CodeLens [ ] = [ ] ;
37- tree . TopLevelTypeDefinitions . forEach ( node => OmniSharpCodeLensProvider . _convertQuickFix ( ret , document . fileName , node ) ) ;
38- return ret ;
39- } ) ;
40- }
41-
42- private static _convertQuickFix ( bucket : CodeLens [ ] , fileName :string , node : protocol . Node ) : void {
43-
44- if ( node . Kind === 'MethodDeclaration' && OmniSharpCodeLensProvider . filteredSymbolNames [ node . Location . Text ] ) {
45- return ;
46- }
47-
48- let lens = new OmniSharpCodeLens ( fileName , toRange ( node . Location ) ) ;
49- bucket . push ( lens ) ;
50-
51- for ( let child of node . ChildNodes ) {
52- OmniSharpCodeLensProvider . _convertQuickFix ( bucket , fileName , child ) ;
53- }
54- }
55-
56- resolveCodeLens ( codeLens : CodeLens , token : CancellationToken ) : Thenable < CodeLens > {
57- if ( codeLens instanceof OmniSharpCodeLens ) {
58-
59- let req = < protocol . FindUsagesRequest > {
60- Filename : codeLens . fileName ,
61- Line : codeLens . range . start . line + 1 ,
62- Column : codeLens . range . start . character + 1 ,
63- OnlyThisFile : false ,
64- ExcludeDefinition : true
65- } ;
66-
67- return serverUtils . findUsages ( this . _server , req , token ) . then ( res => {
68- if ( ! res || ! Array . isArray ( res . QuickFixes ) ) {
69- return ;
70- }
71-
72- let len = res . QuickFixes . length ;
73- codeLens . command = {
74- title : len === 1 ? '1 reference' : `${ len } references` ,
75- command : 'editor.action.showReferences' ,
76- arguments : [ Uri . file ( req . Filename ) , codeLens . range . start , res . QuickFixes . map ( toLocation ) ]
77- } ;
78-
79- return codeLens ;
80- } ) ;
81- }
82- }
26+ private static filteredSymbolNames : { [ name : string ] : boolean } = {
27+ 'Equals' : true ,
28+ 'Finalize' : true ,
29+ 'GetHashCode' : true ,
30+ 'ToString' : true
31+ } ;
32+
33+ provideCodeLenses ( document : TextDocument , token : CancellationToken ) : CodeLens [ ] | Thenable < CodeLens [ ] > {
34+
35+ return serverUtils . currentFileMembersAsTree ( this . _server , { Filename : document . fileName } , token ) . then ( tree => {
36+ let ret : CodeLens [ ] = [ ] ;
37+ tree . TopLevelTypeDefinitions . forEach ( node => OmniSharpCodeLensProvider . _convertQuickFix ( ret , document . fileName , node ) ) ;
38+ return ret ;
39+ } ) ;
40+ }
41+
42+ private static _convertQuickFix ( bucket : CodeLens [ ] , fileName : string , node : protocol . Node ) : void {
43+
44+ if ( node . Kind === 'MethodDeclaration' && OmniSharpCodeLensProvider . filteredSymbolNames [ node . Location . Text ] ) {
45+ return ;
46+ }
47+
48+ let lens = new OmniSharpCodeLens ( fileName , toRange ( node . Location ) ) ;
49+ bucket . push ( lens ) ;
50+
51+ for ( let child of node . ChildNodes ) {
52+ OmniSharpCodeLensProvider . _convertQuickFix ( bucket , fileName , child ) ;
53+ }
54+
55+ let testFeature = node . Features . find ( value => value . startsWith ( 'XunitTestMethod' ) ) ;
56+ if ( testFeature ) {
57+ // this test method has a test feature
58+ let testMethod = testFeature . split ( ':' ) [ 1 ] ;
59+
60+ bucket . push ( new CodeLens ( toRange ( node . Location ) , { title : "run test" , command : 'dotnet.test.run' , arguments : [ testMethod , fileName ] } ) ) ;
61+ bucket . push ( new CodeLens ( toRange ( node . Location ) , { title : "debug test" , command : 'dotnet.test.debug' , arguments : [ testMethod , fileName ] } ) ) ;
62+ }
63+ }
64+
65+ resolveCodeLens ( codeLens : CodeLens , token : CancellationToken ) : Thenable < CodeLens > {
66+ if ( codeLens instanceof OmniSharpCodeLens ) {
67+
68+ let req = < protocol . FindUsagesRequest > {
69+ Filename : codeLens . fileName ,
70+ Line : codeLens . range . start . line + 1 ,
71+ Column : codeLens . range . start . character + 1 ,
72+ OnlyThisFile : false ,
73+ ExcludeDefinition : true
74+ } ;
75+
76+ return serverUtils . findUsages ( this . _server , req , token ) . then ( res => {
77+ if ( ! res || ! Array . isArray ( res . QuickFixes ) ) {
78+ return ;
79+ }
80+
81+ let len = res . QuickFixes . length ;
82+ codeLens . command = {
83+ title : len === 1 ? '1 reference' : `${ len } references` ,
84+ command : 'editor.action.showReferences' ,
85+ arguments : [ Uri . file ( req . Filename ) , codeLens . range . start , res . QuickFixes . map ( toLocation ) ]
86+ } ;
87+
88+ return codeLens ;
89+ } ) ;
90+ }
91+ }
8392}
0 commit comments