@@ -2,11 +2,8 @@ import { existsSync } from 'fs';
22import { join } from 'path' ;
33import { format } from 'util' ;
44import {
5- ConfigurationTarget ,
65 ExtensionContext ,
7- FileType ,
86 TextDocument ,
9- Uri ,
107 commands ,
118 extensions ,
129 tasks ,
@@ -18,19 +15,19 @@ import {
1815 getBazelTerminal ,
1916} from './bazelLangaugeServerTerminal' ;
2017import { BazelTaskManager } from './bazelTaskManager' ;
21- import { getBazelProjectFile } from './bazelprojectparser' ;
2218import { Commands , executeJavaLanguageServerCommand } from './commands' ;
2319import { registerLSClient } from './loggingTCPServer' ;
20+ import { ProjectViewManager } from './projectViewManager' ;
2421import { BazelRunTargetProvider } from './provider/bazelRunTargetProvider' ;
2522import { BazelTaskProvider } from './provider/bazelTaskProvider' ;
26- import { ExcludeConfig , FileWatcherExcludeConfig } from './types' ;
2723import {
2824 getWorkspaceRoot ,
2925 initBazelProjectFile ,
3026 isBazelWorkspaceRoot ,
3127} from './util' ;
3228
3329const workspaceRoot = getWorkspaceRoot ( ) ;
30+ const workspaceRootName = workspaceRoot . split ( '/' ) . reverse ( ) [ 0 ] ;
3431
3532export async function activate ( context : ExtensionContext ) {
3633 // activates
@@ -39,8 +36,8 @@ export async function activate(context: ExtensionContext) {
3936 // register TCP port with LS
4037 // project view should reflect what's in the LS
4138 // show any directories listed in the .bazelproject file
42- // fetch all projects loaded into LS and display those too
43- // show both .vscode and . eclipse folders
39+ // fetch all projects loaded into LS and display those as well
40+ // show . eclipse folder
4441 //
4542
4643 window . registerTreeDataProvider (
@@ -120,6 +117,13 @@ export async function activate(context: ExtensionContext) {
120117 )
121118 ) ;
122119
120+ context . subscriptions . push (
121+ commands . registerCommand (
122+ Commands . CONVERT_PROJECT_WORKSPACE ,
123+ ProjectViewManager . covertToMultiRoot
124+ )
125+ ) ;
126+
123127 // trigger a refresh of the tree view when any task get executed
124128 tasks . onDidStartTask ( ( _ ) => BazelRunTargetProvider . instance . refresh ( ) ) ;
125129 tasks . onDidEndTask ( ( _ ) => BazelRunTargetProvider . instance . refresh ( ) ) ;
@@ -214,117 +218,8 @@ function toggleBazelProjectSyncStatus(doc: TextDocument) {
214218 }
215219}
216220
217- async function syncProjectViewDirectories ( ) {
218- if ( workspaceRoot ) {
219- BazelLanguageServerTerminal . debug ( 'Syncing bazel project view' ) ;
220- const displayFolders = new Set < string > ( [ '.eclipse' , '.vscode' ] ) ; // TODO bubble this out to a setting
221- try {
222- const bazelProjectFile = await getBazelProjectFile ( ) ;
223- let viewAll = false ;
224- if ( bazelProjectFile . directories . includes ( '.' ) ) {
225- viewAll = true ;
226- } else {
227- bazelProjectFile . directories . forEach ( ( d ) => {
228- const dirRoot = d . split ( '/' ) . filter ( ( x ) => x ) [ 0 ] ;
229- displayFolders . add ( dirRoot ) ;
230- } ) ;
231- bazelProjectFile . targets . forEach ( ( t ) =>
232- displayFolders . add (
233- t . replace ( '//' , '' ) . replace ( / : .* / , '' ) . replace ( / \/ .* / , '' )
234- )
235- ) ;
236- }
237-
238- workspace . fs . readDirectory ( Uri . parse ( workspaceRoot ) ) . then ( async ( val ) => {
239- const dirs = val . filter ( ( x ) => x [ 1 ] !== FileType . File ) . map ( ( d ) => d [ 0 ] ) ;
240- const workspaceFilesConfig = workspace . getConfiguration ( 'files' ) ;
241- const filesExclude = workspaceFilesConfig . get (
242- 'exclude'
243- ) as ExcludeConfig ;
244- dirs . forEach (
245- ( d ) => ( filesExclude [ d ] = viewAll ? false : ! displayFolders . has ( d ) )
246- ) ;
247- await workspaceFilesConfig . update (
248- 'exclude' ,
249- filesExclude ,
250- ConfigurationTarget . Workspace
251- ) ;
252-
253- // if the updateFileWatcherExclusion setting is enabled
254- if (
255- workspace
256- . getConfiguration ( 'bazel.projectview' )
257- . get ( 'updateFileWatcherExclusion' )
258- ) {
259- BazelLanguageServerTerminal . debug (
260- 'updating files.watcherExclude setting'
261- ) ;
262-
263- const filesWatcherExclude =
264- workspaceFilesConfig . get < FileWatcherExcludeConfig > (
265- 'watcherExclude' ,
266- { }
267- ) ;
268-
269- const fileWatcherKeys = Object . keys ( filesWatcherExclude ) ;
270- const hasOldEntry = fileWatcherKeys . filter (
271- ( k ) => k . includes ( '.vscode' ) && k . includes ( '.eclipse' )
272- ) . length ;
273-
274- const fileWatcherExcludePattern = viewAll
275- ? ''
276- : `**/!(${ Array . from ( displayFolders ) . join ( '|' ) } )/**` ;
277-
278- if ( viewAll ) {
279- // if viewAll and existing config doesn't contain .vscode/.eclipse return
280- if ( ! hasOldEntry ) {
281- return ;
282- }
283- } else {
284- // if !viewAll and existing config contains identical entry return
285- if ( fileWatcherKeys . includes ( fileWatcherExcludePattern ) ) {
286- return ;
287- }
288- }
289-
290- // copy the old config obj, but remove any previous exclude based on the .bazelproject file
291- const newFilesWatcherExclude : FileWatcherExcludeConfig = { } ;
292- for ( const val in filesWatcherExclude ) {
293- if ( ! ( val . includes ( '.eclipse' ) && val . includes ( '.vscode' ) ) ) {
294- newFilesWatcherExclude [ val ] = filesWatcherExclude [ val ] ;
295- }
296- }
297-
298- if ( fileWatcherExcludePattern ) {
299- newFilesWatcherExclude [ fileWatcherExcludePattern ] = true ;
300- }
301-
302- // reload the workspace to make the updated file watcher exclusions take effect
303- workspaceFilesConfig
304- . update ( 'watcherExclude' , newFilesWatcherExclude )
305- . then ( ( x ) =>
306- window
307- . showWarningMessage (
308- 'File watcher exclusions are out of date. Please reload the window to apply the change' ,
309- ...[ 'Reload' , 'Ignore' ]
310- )
311- . then ( ( opt ) => {
312- if ( opt === 'Reload' ) {
313- commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
314- }
315- if ( opt === 'Ignore' ) {
316- workspace
317- . getConfiguration ( 'bazel.projectview' )
318- . update ( 'updateFileWatcherExclusion' , false ) ;
319- }
320- } )
321- ) ;
322- }
323- } ) ;
324- } catch ( err ) {
325- throw new Error ( `Could not read bazelproject file: ${ err } ` ) ;
326- }
327- }
221+ function syncProjectViewDirectories ( ) {
222+ ProjectViewManager . updateProjectView ( ) ;
328223}
329224
330225function openBazelProjectFile ( ) {
0 commit comments