@@ -5,28 +5,30 @@ import * as fs from 'fs';
55import * as fse from 'fs-extra' ;
66import * as os from 'os' ;
77import * 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' ;
1010import { LanguageClient } from 'vscode-languageclient/node' ;
1111import { apiManager } from './apiManager' ;
12+ import { ClientErrorHandler } from './clientErrorHandler' ;
1213import { Commands } from './commands' ;
1314import { ClientStatus , ExtensionAPI } from './extension.api' ;
1415import * as fileEventHandler from './fileEventHandler' ;
1516import { HEAP_DUMP_LOCATION , prepareExecutable } from './javaServerStarter' ;
1617import { initializeLogFile , logger } from './log' ;
1718import { cleanupLombokCache } from "./lombokSupport" ;
1819import { markdownPreviewProvider } from "./markdownPreviewProvider" ;
20+ import { OutputInfoCollector } from './outputInfoCollector' ;
1921import { collectJavaExtensions , getBundlesToReload , isContributedPartUpdated } from './plugin' ;
2022import { registerClientProviders } from './providerDispatcher' ;
2123import { initialize as initializeRecommendation } from './recommendation' ;
2224import * as requirements from './requirements' ;
2325import { runtimeStatusBarProvider } from './runtimeStatusBarProvider' ;
2426import { 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' ;
2628import { snippetCompletionProvider } from './snippetCompletionProvider' ;
2729import { StandardLanguageClient } from './standardLanguageClient' ;
2830import { 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' ;
3032import glob = require( 'glob' ) ;
3133
3234const syntaxClient : SyntaxLanguageClient = new SyntaxLanguageClient ( ) ;
@@ -36,51 +38,6 @@ const extensionName = 'Language Support for Java';
3638let storagePath : string ;
3739let clientLogFile : string ;
3840
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-
8441/**
8542 * Shows a message about the server crashing due to an out of memory issue
8643 */
@@ -118,46 +75,6 @@ function getHeapDumpFolderFromSettings(): string {
11875 return results [ 1 ] || results [ 2 ] || results [ 3 ] ;
11976}
12077
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- }
16178
16279export function activate ( context : ExtensionContext ) : Promise < ExtensionAPI > {
16380 context . subscriptions . push ( markdownPreviewProvider ) ;
@@ -563,48 +480,6 @@ async function ensureNoBuildToolConflicts(context: ExtensionContext, clientOptio
563480 return true ;
564481}
565482
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-
608483async function promptUserForStandardServer ( config : WorkspaceConfiguration ) : Promise < boolean > {
609484 const choice : string = await window . showInformationMessage ( "The workspace contains Java projects. Would you like to import them?" , "Yes" , "Always" , "Later" ) ;
610485 switch ( choice ) {
@@ -632,36 +507,6 @@ async function promptUserForStandardServer(config: WorkspaceConfiguration): Prom
632507 }
633508}
634509
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-
665510export function deactivate ( ) : Promise < void [ ] > {
666511 return Promise . all < void > ( [
667512 standardClient . stop ( ) ,
@@ -964,15 +809,6 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
964809 } ) ;
965810}
966811
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-
976812async function getTriggerFiles ( ) : Promise < string [ ] > {
977813 const openedJavaFiles = [ ] ;
978814 const activeJavaFile = getJavaFilePathOfTextDocument ( window . activeTextEditor && window . activeTextEditor . document ) ;
0 commit comments