@@ -5,28 +5,30 @@ import * as fs from 'fs';
5
5
import * as fse from 'fs-extra' ;
6
6
import * as os from 'os' ;
7
7
import * as path from 'path' ;
8
- import { CodeActionContext , CodeActionTriggerKind , commands , ConfigurationTarget , Diagnostic , env , EventEmitter , ExtensionContext , extensions , IndentAction , InputBoxOptions , languages , OutputChannel , RelativePattern , TextDocument , UIKind , Uri , version , ViewColumn , window , workspace , WorkspaceConfiguration } from 'vscode' ;
9
- import { CancellationToken , CloseAction , CodeActionParams , CodeActionRequest , Command , DidChangeConfigurationNotification , ErrorAction , ErrorHandler , ExecuteCommandParams , ExecuteCommandRequest , LanguageClientOptions , Message , RevealOutputChannelOn } from 'vscode-languageclient' ;
8
+ import { CodeActionContext , CodeActionTriggerKind , commands , ConfigurationTarget , Diagnostic , env , EventEmitter , ExtensionContext , extensions , IndentAction , InputBoxOptions , languages , RelativePattern , TextDocument , UIKind , Uri , ViewColumn , window , workspace , WorkspaceConfiguration } from 'vscode' ;
9
+ import { CancellationToken , CodeActionParams , CodeActionRequest , Command , DidChangeConfigurationNotification , ExecuteCommandParams , ExecuteCommandRequest , LanguageClientOptions , RevealOutputChannelOn } from 'vscode-languageclient' ;
10
10
import { LanguageClient } from 'vscode-languageclient/node' ;
11
11
import { apiManager } from './apiManager' ;
12
+ import { ClientErrorHandler } from './clientErrorHandler' ;
12
13
import { Commands } from './commands' ;
13
14
import { ClientStatus , ExtensionAPI } from './extension.api' ;
14
15
import * as fileEventHandler from './fileEventHandler' ;
15
16
import { HEAP_DUMP_LOCATION , prepareExecutable } from './javaServerStarter' ;
16
17
import { initializeLogFile , logger } from './log' ;
17
18
import { cleanupLombokCache } from "./lombokSupport" ;
18
19
import { markdownPreviewProvider } from "./markdownPreviewProvider" ;
20
+ import { OutputInfoCollector } from './outputInfoCollector' ;
19
21
import { collectJavaExtensions , getBundlesToReload , isContributedPartUpdated } from './plugin' ;
20
22
import { registerClientProviders } from './providerDispatcher' ;
21
23
import { initialize as initializeRecommendation } from './recommendation' ;
22
24
import * as requirements from './requirements' ;
23
25
import { runtimeStatusBarProvider } from './runtimeStatusBarProvider' ;
24
26
import { serverStatusBarProvider } from './serverStatusBarProvider' ;
25
- import { ACTIVE_BUILD_TOOL_STATE , getJavaServerMode , handleTextBlockClosing , onConfigurationChange , ServerMode } from './settings' ;
27
+ import { ACTIVE_BUILD_TOOL_STATE , cleanWorkspaceFileName , getJavaServerMode , handleTextBlockClosing , onConfigurationChange , ServerMode } from './settings' ;
26
28
import { snippetCompletionProvider } from './snippetCompletionProvider' ;
27
29
import { StandardLanguageClient } from './standardLanguageClient' ;
28
30
import { SyntaxLanguageClient } from './syntaxLanguageClient' ;
29
- import { convertToGlob , deleteDirectory , ensureExists , getBuildFilePatterns , getExclusionBlob , getInclusionPatternsFromNegatedExclusion , getJavaConfiguration } from './utils' ;
31
+ import { convertToGlob , deleteDirectory , ensureExists , getBuildFilePatterns , getExclusionBlob , getInclusionPatternsFromNegatedExclusion , getJavaConfig , getJavaConfiguration , hasBuildToolConflicts } from './utils' ;
30
32
import glob = require( 'glob' ) ;
31
33
32
34
const syntaxClient : SyntaxLanguageClient = new SyntaxLanguageClient ( ) ;
@@ -36,51 +38,6 @@ const extensionName = 'Language Support for Java';
36
38
let storagePath : string ;
37
39
let clientLogFile : string ;
38
40
39
- export const cleanWorkspaceFileName = '.cleanWorkspace' ;
40
-
41
- export class ClientErrorHandler implements ErrorHandler {
42
- private restarts : number [ ] ;
43
-
44
- constructor ( private name : string ) {
45
- this . restarts = [ ] ;
46
- }
47
-
48
- public error ( _error : Error , _message : Message , count : number ) : ErrorAction {
49
- if ( count && count <= 3 ) {
50
- logger . error ( `${ this . name } server encountered error: ${ _message } , ${ _error && _error . toString ( ) } ` ) ;
51
- return ErrorAction . Continue ;
52
- }
53
-
54
- logger . error ( `${ this . name } server encountered error and will shut down: ${ _message } , ${ _error && _error . toString ( ) } ` ) ;
55
- return ErrorAction . Shutdown ;
56
- }
57
-
58
- public closed ( ) : CloseAction {
59
- this . restarts . push ( Date . now ( ) ) ;
60
- if ( this . restarts . length < 5 ) {
61
- logger . error ( `The ${ this . name } server crashed and will restart.` ) ;
62
- return CloseAction . Restart ;
63
- } else {
64
- const diff = this . restarts [ this . restarts . length - 1 ] - this . restarts [ 0 ] ;
65
- if ( diff <= 3 * 60 * 1000 ) {
66
- const message = `The ${ this . name } server crashed 5 times in the last 3 minutes. The server will not be restarted.` ;
67
- logger . error ( message ) ;
68
- const action = "Show logs" ;
69
- window . showErrorMessage ( message , action ) . then ( selection => {
70
- if ( selection === action ) {
71
- commands . executeCommand ( Commands . OPEN_LOGS ) ;
72
- }
73
- } ) ;
74
- return CloseAction . DoNotRestart ;
75
- }
76
-
77
- logger . error ( `The ${ this . name } server crashed and will restart.` ) ;
78
- this . restarts . shift ( ) ;
79
- return CloseAction . Restart ;
80
- }
81
- }
82
- }
83
-
84
41
/**
85
42
* Shows a message about the server crashing due to an out of memory issue
86
43
*/
@@ -118,46 +75,6 @@ function getHeapDumpFolderFromSettings(): string {
118
75
return results [ 1 ] || results [ 2 ] || results [ 3 ] ;
119
76
}
120
77
121
- export class OutputInfoCollector implements OutputChannel {
122
- private channel : OutputChannel = null ;
123
-
124
- constructor ( public name : string ) {
125
- this . channel = window . createOutputChannel ( this . name ) ;
126
- }
127
-
128
- append ( value : string ) : void {
129
- logger . info ( value ) ;
130
- this . channel . append ( value ) ;
131
- }
132
-
133
- appendLine ( value : string ) : void {
134
- logger . info ( value ) ;
135
- this . channel . appendLine ( value ) ;
136
- }
137
-
138
- replace ( value : string ) : void {
139
- this . clear ( ) ;
140
- this . append ( value ) ;
141
- }
142
-
143
- clear ( ) : void {
144
- this . channel . clear ( ) ;
145
- }
146
-
147
- show ( preserveFocus ?: boolean ) : void ;
148
- show ( column ?: ViewColumn , preserveFocus ?: boolean ) : void ;
149
- show ( column ?: any , preserveFocus ?: any ) {
150
- this . channel . show ( column , preserveFocus ) ;
151
- }
152
-
153
- hide ( ) : void {
154
- this . channel . hide ( ) ;
155
- }
156
-
157
- dispose ( ) : void {
158
- this . channel . dispose ( ) ;
159
- }
160
- }
161
78
162
79
export function activate ( context : ExtensionContext ) : Promise < ExtensionAPI > {
163
80
context . subscriptions . push ( markdownPreviewProvider ) ;
@@ -563,48 +480,6 @@ async function ensureNoBuildToolConflicts(context: ExtensionContext, clientOptio
563
480
return true ;
564
481
}
565
482
566
- export async function hasBuildToolConflicts ( ) : Promise < boolean > {
567
- const projectConfigurationUris : Uri [ ] = await getBuildFilesInWorkspace ( ) ;
568
- const projectConfigurationFsPaths : string [ ] = projectConfigurationUris . map ( ( uri ) => uri . fsPath ) ;
569
- const eclipseDirectories = getDirectoriesByBuildFile ( projectConfigurationFsPaths , [ ] , ".project" ) ;
570
- // ignore the folders that already has .project file (already imported before)
571
- const gradleDirectories = getDirectoriesByBuildFile ( projectConfigurationFsPaths , eclipseDirectories , ".gradle" ) ;
572
- const gradleDirectoriesKts = getDirectoriesByBuildFile ( projectConfigurationFsPaths , eclipseDirectories , ".gradle.kts" ) ;
573
- gradleDirectories . concat ( gradleDirectoriesKts ) ;
574
- const mavenDirectories = getDirectoriesByBuildFile ( projectConfigurationFsPaths , eclipseDirectories , "pom.xml" ) ;
575
- return gradleDirectories . some ( ( gradleDir ) => {
576
- return mavenDirectories . includes ( gradleDir ) ;
577
- } ) ;
578
- }
579
-
580
- async function getBuildFilesInWorkspace ( ) : Promise < Uri [ ] > {
581
- const buildFiles : Uri [ ] = [ ] ;
582
- const inclusionFilePatterns : string [ ] = getBuildFilePatterns ( ) ;
583
- inclusionFilePatterns . push ( "**/.project" ) ;
584
- const inclusionFolderPatterns : string [ ] = getInclusionPatternsFromNegatedExclusion ( ) ;
585
- // Since VS Code API does not support put negated exclusion pattern in findFiles(),
586
- // here we first parse the negated exclusion to inclusion and do the search.
587
- if ( inclusionFilePatterns . length > 0 && inclusionFolderPatterns . length > 0 ) {
588
- buildFiles . push ( ...await workspace . findFiles ( convertToGlob ( inclusionFilePatterns , inclusionFolderPatterns ) , null /* force not use default exclusion */ ) ) ;
589
- }
590
-
591
- const inclusionBlob : string = convertToGlob ( inclusionFilePatterns ) ;
592
- const exclusionBlob : string = getExclusionBlob ( ) ;
593
- if ( inclusionBlob ) {
594
- buildFiles . push ( ...await workspace . findFiles ( inclusionBlob , exclusionBlob ) ) ;
595
- }
596
-
597
- return buildFiles ;
598
- }
599
-
600
- function getDirectoriesByBuildFile ( inclusions : string [ ] , exclusions : string [ ] , fileName : string ) : string [ ] {
601
- return inclusions . filter ( ( fsPath ) => fsPath . endsWith ( fileName ) ) . map ( ( fsPath ) => {
602
- return path . dirname ( fsPath ) ;
603
- } ) . filter ( ( inclusion ) => {
604
- return ! exclusions . includes ( inclusion ) ;
605
- } ) ;
606
- }
607
-
608
483
async function promptUserForStandardServer ( config : WorkspaceConfiguration ) : Promise < boolean > {
609
484
const choice : string = await window . showInformationMessage ( "The workspace contains Java projects. Would you like to import them?" , "Yes" , "Always" , "Later" ) ;
610
485
switch ( choice ) {
@@ -632,36 +507,6 @@ async function promptUserForStandardServer(config: WorkspaceConfiguration): Prom
632
507
}
633
508
}
634
509
635
- export function getJavaConfig ( javaHome : string ) {
636
- const origConfig = getJavaConfiguration ( ) ;
637
- const javaConfig = JSON . parse ( JSON . stringify ( origConfig ) ) ;
638
- javaConfig . home = javaHome ;
639
- // Since source & output path are project specific settings. To avoid pollute other project,
640
- // we avoid reading the value from the global scope.
641
- javaConfig . project . outputPath = origConfig . inspect < string > ( "project.outputPath" ) . workspaceValue ;
642
- javaConfig . project . sourcePaths = origConfig . inspect < string [ ] > ( "project.sourcePaths" ) . workspaceValue ;
643
-
644
- const editorConfig = workspace . getConfiguration ( 'editor' ) ;
645
- javaConfig . format . insertSpaces = editorConfig . get ( 'insertSpaces' ) ;
646
- javaConfig . format . tabSize = editorConfig . get ( 'tabSize' ) ;
647
- const androidSupport = javaConfig . jdt . ls . androidSupport . enabled ;
648
- switch ( androidSupport ) {
649
- case "auto" :
650
- javaConfig . jdt . ls . androidSupport . enabled = version . includes ( "insider" ) ? true : false ;
651
- break ;
652
- case "on" :
653
- javaConfig . jdt . ls . androidSupport . enabled = true ;
654
- break ;
655
- case "off" :
656
- javaConfig . jdt . ls . androidSupport . enabled = false ;
657
- break ;
658
- default :
659
- javaConfig . jdt . ls . androidSupport . enabled = false ;
660
- break ;
661
- }
662
- return javaConfig ;
663
- }
664
-
665
510
export function deactivate ( ) : Promise < void [ ] > {
666
511
return Promise . all < void > ( [
667
512
standardClient . stop ( ) ,
@@ -964,15 +809,6 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
964
809
} ) ;
965
810
}
966
811
967
- export function applyWorkspaceEdit ( obj , languageClient ) : Thenable < boolean > {
968
- const edit = languageClient . protocol2CodeConverter . asWorkspaceEdit ( obj ) ;
969
- if ( edit ) {
970
- return workspace . applyEdit ( edit ) ;
971
- } else {
972
- return Promise . resolve ( true ) ;
973
- }
974
- }
975
-
976
812
async function getTriggerFiles ( ) : Promise < string [ ] > {
977
813
const openedJavaFiles = [ ] ;
978
814
const activeJavaFile = getJavaFilePathOfTextDocument ( window . activeTextEditor && window . activeTextEditor . document ) ;
0 commit comments