11"use strict" ;
22
33import * as vscode from 'vscode' ;
4- import { Location , ExtensionContext , Position , SymbolKind , SymbolInformation } from 'vscode' ;
4+ import { Location , ExtensionContext , Position } from 'vscode' ;
55import * as Locate from './locate/locate' ;
66import * as path from 'path' ;
77import * as cp from 'child_process' ;
@@ -13,6 +13,7 @@ import { Config as LintConfig } from './lint/lintConfig';
1313import * as debounce from 'lodash/debounce' ;
1414
1515import { registerHighlightProvider } from './providers/highlight' ;
16+ import { registerIntellisenseProvider } from './providers/intellisense' ;
1617
1718export function activate ( context : ExtensionContext ) {
1819 const subs = context . subscriptions ;
@@ -149,71 +150,3 @@ function registerCompletionProvider(ctx: ExtensionContext) {
149150function registerFormatter ( ctx : ExtensionContext ) {
150151 new RubyDocumentFormattingEditProvider ( ) . register ( ctx ) ;
151152}
152-
153- function registerIntellisenseProvider ( ctx : ExtensionContext ) {
154- // for locate: if it's a project, use the root, othewise, don't bother
155- if ( vscode . workspace . getConfiguration ( 'ruby' ) . intellisense == 'rubyLocate' ) {
156- if ( vscode . workspace . rootPath ) {
157- const refreshLocate = ( ) => {
158- let progressOptions = { location : vscode . ProgressLocation . Window , title : 'Indexing Ruby source files' } ;
159- vscode . window . withProgress ( progressOptions , ( ) => locate . walk ( ) ) ;
160- } ;
161- const settings : any = vscode . workspace . getConfiguration ( "ruby.locate" ) || { } ;
162- let locate = new Locate ( vscode . workspace . rootPath , settings ) ;
163- refreshLocate ( ) ;
164- ctx . subscriptions . push ( vscode . commands . registerCommand ( 'ruby.reloadProject' , refreshLocate ) ) ;
165-
166- const watch = vscode . workspace . createFileSystemWatcher ( settings . include ) ;
167- watch . onDidChange ( uri => locate . parse ( uri . fsPath ) ) ;
168- watch . onDidCreate ( uri => locate . parse ( uri . fsPath ) ) ;
169- watch . onDidDelete ( uri => locate . rm ( uri . fsPath ) ) ;
170- const locationConverter = match => new vscode . Location ( vscode . Uri . file ( match . file ) , new vscode . Position ( match . line , match . char ) ) ;
171- const defProvider = {
172- provideDefinition : ( doc , pos ) => {
173- const txt = doc . getText ( doc . getWordRangeAtPosition ( pos ) ) ;
174- return locate . find ( txt ) . then ( matches => matches . map ( locationConverter ) ) ;
175- }
176- } ;
177- ctx . subscriptions . push ( vscode . languages . registerDefinitionProvider ( [ 'ruby' , 'erb' ] , defProvider ) ) ;
178- const symbolKindTable = {
179- class : ( ) => SymbolKind . Class ,
180- module : ( ) => SymbolKind . Module ,
181- method : symbolInfo => symbolInfo . name === 'initialize' ? SymbolKind . Constructor : SymbolKind . Method ,
182- classMethod : ( ) => SymbolKind . Method ,
183- } ;
184- const defaultSymbolKind = symbolInfo => {
185- console . warn ( `Unknown symbol type: ${ symbolInfo . type } ` ) ;
186- return SymbolKind . Variable ;
187- } ;
188- // NOTE: Workaround for high CPU usage on IPC (channel.onread) when too many symbols returned.
189- // For channel.onread see issue like this: https://github.com/Microsoft/vscode/issues/6026
190- const numOfSymbolLimit = 3000 ;
191- const symbolsConverter = matches => matches . slice ( 0 , numOfSymbolLimit ) . map ( match => {
192- const symbolKind = ( symbolKindTable [ match . type ] || defaultSymbolKind ) ( match ) ;
193- return new SymbolInformation ( match . name , symbolKind , match . containerName , locationConverter ( match ) ) ;
194- } ) ;
195- const docSymbolProvider = {
196- provideDocumentSymbols : ( document , token ) => {
197- return locate . listInFile ( document . fileName ) . then ( symbolsConverter ) ;
198- }
199- } ;
200- ctx . subscriptions . push ( vscode . languages . registerDocumentSymbolProvider ( [ 'ruby' , 'erb' ] , docSymbolProvider ) ) ;
201- const workspaceSymbolProvider = {
202- provideWorkspaceSymbols : ( query , token ) => {
203- return locate . query ( query ) . then ( symbolsConverter ) ;
204- }
205- } ;
206- ctx . subscriptions . push ( vscode . languages . registerWorkspaceSymbolProvider ( workspaceSymbolProvider ) ) ;
207- } else {
208- var rubyLocateUnavailable = ( ) => {
209- vscode . window . showInformationMessage ( 'There is not an open workspace for rubyLocate to reload.' ) ;
210- } ;
211- ctx . subscriptions . push ( vscode . commands . registerCommand ( 'ruby.reloadProject' , rubyLocateUnavailable ) ) ;
212- }
213- } else {
214- var rubyLocateDisabled = ( ) => {
215- vscode . window . showInformationMessage ( 'The `ruby.intellisense` configuration is not set to use rubyLocate.' )
216- } ;
217- ctx . subscriptions . push ( vscode . commands . registerCommand ( 'ruby.reloadProject' , rubyLocateDisabled ) ) ;
218- }
219- }
0 commit comments