@@ -4,13 +4,13 @@ import * as vscode from 'vscode';
44import { Location , ExtensionContext , Position } from 'vscode' ;
55import * as Locate from './locate/locate' ;
66import * as path from 'path' ;
7- import * as cp from 'child_process' ;
87import { LintCollection } from './lint/lintCollection' ;
98import * as utils from './utils' ;
109import { registerTaskProvider } from './task/rake' ;
1110import { Config as LintConfig } from './lint/lintConfig' ;
1211import * as debounce from 'lodash/debounce' ;
1312
13+ import { registerCompletionProvider } from './providers/completion' ;
1414import { registerFormatter } from './providers/formatter' ;
1515import { registerHighlightProvider } from './providers/highlight' ;
1616import { registerIntellisenseProvider } from './providers/intellisense' ;
@@ -82,67 +82,3 @@ function registerLinters(ctx: ExtensionContext) {
8282 // run against all of the current open files
8383 vscode . window . visibleTextEditors . forEach ( executeLinting ) ;
8484}
85-
86- function registerCompletionProvider ( ctx : ExtensionContext ) {
87- if ( vscode . workspace . getConfiguration ( 'ruby' ) . codeCompletion == 'rcodetools' ) {
88- const completeCommand = function ( args ) {
89- let rctCompletePath = vscode . workspace . getConfiguration ( 'ruby.rctComplete' ) . get ( 'commandPath' , 'rct-complete' ) ;
90- args . push ( '--interpreter' ) ;
91- args . push ( vscode . workspace . getConfiguration ( 'ruby.interpreter' ) . get ( 'commandPath' , 'ruby' ) ) ;
92- if ( process . platform === 'win32' )
93- return cp . spawn ( 'cmd' , [ '/c' , rctCompletePath ] . concat ( args ) ) ;
94- return cp . spawn ( rctCompletePath , args ) ;
95- }
96-
97- const completeTest = completeCommand ( [ '--help' ] ) ;
98- completeTest . on ( 'exit' , ( ) => {
99- ctx . subscriptions . push (
100- vscode . languages . registerCompletionItemProvider (
101- /** selector */ 'ruby' ,
102- /** provider */ {
103- provideCompletionItems : function completionProvider ( document , position , token ) {
104- return new Promise ( ( resolve , reject ) => {
105- const line = position . line + 1 ;
106- const column = position . character ;
107- let child = completeCommand ( [
108- '--completion-class-info' ,
109- '--dev' ,
110- '--fork' ,
111- '--line=' + line ,
112- '--column=' + column
113- ] ) ;
114- let outbuf = [ ] ,
115- errbuf = [ ] ;
116- child . stderr . on ( 'data' , ( data ) => errbuf . push ( data ) ) ;
117- child . stdout . on ( 'data' , ( data ) => outbuf . push ( data ) ) ;
118- child . stdout . on ( 'end' , ( ) => {
119- if ( errbuf . length > 0 ) return reject ( Buffer . concat ( errbuf ) . toString ( ) ) ;
120- let completionItems = [ ] ;
121- Buffer . concat ( outbuf ) . toString ( ) . split ( '\n' ) . forEach ( function ( elem ) {
122- let items = elem . split ( '\t' ) ;
123- if ( / ^ [ ^ \w ] / . test ( items [ 0 ] ) ) return ;
124- if ( items [ 0 ] . trim ( ) . length === 0 ) return ;
125- let completionItem = new vscode . CompletionItem ( items [ 0 ] ) ;
126- completionItem . detail = items [ 1 ] ;
127- completionItem . documentation = items [ 1 ] ;
128- completionItem . filterText = items [ 0 ] ;
129- completionItem . insertText = items [ 0 ] ;
130- completionItem . label = items [ 0 ] ;
131- completionItem . kind = vscode . CompletionItemKind . Method ;
132- completionItems . push ( completionItem ) ;
133- } , this ) ;
134- if ( completionItems . length === 0 )
135- return reject ( [ ] ) ;
136- return resolve ( completionItems ) ;
137- } ) ;
138- child . stdin . end ( document . getText ( ) ) ;
139- } ) ;
140- }
141- } ,
142- /** triggerCharacters */ ...[ '.' ]
143- )
144- )
145- } ) ;
146- completeTest . on ( 'error' , ( ) => 0 ) ;
147- }
148- }
0 commit comments