33import * as vscode from 'vscode' ;
44import * as fs from 'fs' ;
55
6- import { ConnectionManager } from './connection' ;
76import { ConnectionConfiguration } from './configuration' ;
8- import { OutputChannelLogger } from './logging/outputchannel' ;
9- import { Reporter } from './telemetry/telemetry' ;
7+ import { ConnectionHandler } from './handler' ;
8+ import { StdioConnectionHandler } from './handlers/stdio' ;
9+ import { TcpConnectionHandler } from './handlers/tcp' ;
1010import { IFeature } from './feature' ;
11- import { PuppetStatusBar } from './PuppetStatusBar' ;
12- import { ISettings , legacySettings , settingsFromWorkspace } from './settings' ;
1311import { DebugConfigurationFeature } from './feature/DebugConfigurationFeature' ;
1412import { FormatDocumentFeature } from './feature/FormatDocumentFeature' ;
1513import { NodeGraphFeature } from './feature/NodeGraphFeature' ;
1614import { PDKFeature } from './feature/PDKFeature' ;
1715import { PuppetResourceFeature } from './feature/PuppetResourceFeature' ;
16+ import { ProtocolType , ConnectionType , IConnectionConfiguration } from './interfaces' ;
1817import { ILogger } from './logging' ;
19- import { ProtocolType , ConnectionType } from './interfaces' ;
18+ import { OutputChannelLogger } from './logging/outputchannel' ;
19+ import { PuppetCommandStrings } from './messages' ;
20+ import { PuppetStatusBar } from './PuppetStatusBar' ;
21+ import { ISettings , legacySettings , settingsFromWorkspace } from './settings' ;
22+ import { Reporter } from './telemetry/telemetry' ;
2023
21- var connManager : ConnectionManager ;
2224const langID = 'puppet' ; // don't change this
25+ let extContext : vscode . ExtensionContext ;
26+ let connectionHandler : ConnectionHandler ;
27+ let settings : ISettings ;
28+ let logger : OutputChannelLogger ;
29+ let statusBar : PuppetStatusBar ;
30+ let configSettings : IConnectionConfiguration ;
2331let extensionFeatures : IFeature [ ] = [ ] ;
2432
2533export function activate ( context : vscode . ExtensionContext ) {
26- notifyOnNewExtensionVersion ( context ) ;
34+ extContext = context ;
35+
36+ notifyOnNewExtensionVersion ( extContext ) ;
2737 checkForLegacySettings ( ) ;
2838
29- context . subscriptions . push ( new Reporter ( context ) ) ;
30- const settings : ISettings = settingsFromWorkspace ( ) ;
31- var logger = new OutputChannelLogger ( settings ) ,
32- statusBar = new PuppetStatusBar ( langID , context , logger ) ,
33- configSettings = new ConnectionConfiguration ( ) ;
39+ context . subscriptions . push ( new Reporter ( extContext ) ) ;
3440
35- connManager = new ConnectionManager ( context , logger , statusBar , configSettings ) ;
41+ settings = settingsFromWorkspace ( ) ;
42+ logger = new OutputChannelLogger ( settings ) ;
43+ statusBar = new PuppetStatusBar ( langID , context , logger ) ;
44+ configSettings = new ConnectionConfiguration ( ) ;
3645
37- checkInstallDirectory ( configSettings , logger ) ;
46+ if ( checkInstallDirectory ( configSettings , logger ) === false ) {
47+ // If this returns false, then we needed a local directory
48+ // but did not find it, so we should abort here
49+ // If we return true, we can continue
50+ // This can be revisited to enable disabling language server portion
51+ return ;
52+ }
53+
54+ switch ( configSettings . protocol ) {
55+ case ProtocolType . STDIO :
56+ connectionHandler = new StdioConnectionHandler ( extContext , settings , statusBar , logger , configSettings ) ;
57+ break ;
58+ case ProtocolType . TCP :
59+ connectionHandler = new TcpConnectionHandler ( extContext , settings , statusBar , logger , configSettings ) ;
60+ break ;
61+ }
3862
3963 extensionFeatures = [
40- new DebugConfigurationFeature ( logger , context ) ,
41- new FormatDocumentFeature ( langID , connManager , settings , logger , context ) ,
42- new NodeGraphFeature ( langID , connManager , logger , context ) ,
43- new PDKFeature ( context , logger ) ,
44- new PuppetResourceFeature ( context , connManager , logger )
64+ new DebugConfigurationFeature ( logger , extContext ) ,
65+ new FormatDocumentFeature ( langID , connectionHandler , settings , logger , extContext ) ,
66+ new NodeGraphFeature ( langID , connectionHandler , logger , extContext ) ,
67+ new PDKFeature ( extContext , logger ) ,
68+ new PuppetResourceFeature ( extContext , connectionHandler , logger )
4569 ] ;
4670
47- connManager . start ( configSettings ) ;
71+ extContext . subscriptions . push ( vscode . commands . registerCommand ( PuppetCommandStrings . PuppetRestartSessionCommandId ,
72+ ( ) => {
73+
74+ }
75+ ) ) ;
4876}
4977
5078export function deactivate ( ) {
@@ -53,9 +81,8 @@ export function deactivate() {
5381 feature . dispose ( ) ;
5482 } ) ;
5583
56- if ( connManager !== undefined ) {
57- connManager . stop ( ) ;
58- connManager . dispose ( ) ;
84+ if ( connectionHandler !== undefined ) {
85+ connectionHandler . stop ( ) ;
5986 }
6087}
6188
@@ -76,11 +103,11 @@ function checkForLegacySettings() {
76103 }
77104}
78105
79- function checkInstallDirectory ( configSettings : ConnectionConfiguration , logger : ILogger ) {
106+ function checkInstallDirectory ( configSettings : IConnectionConfiguration , logger : ILogger ) : boolean {
80107 if ( configSettings . protocol === ProtocolType . TCP ) {
81108 if ( configSettings . type === ConnectionType . Remote ) {
82109 // Return if we are connecting to a remote TCP LangServer
83- return ;
110+ return true ;
84111 }
85112 }
86113
@@ -94,9 +121,10 @@ function checkInstallDirectory(configSettings: ConnectionConfiguration, logger:
94121 'https://github.com/lingua-pupuli/puppet-vscode#experience-a-problem' ,
95122 logger
96123 ) ;
97- return null ;
124+ return false ;
98125 } else {
99126 logger . debug ( 'Found a valid Puppet installation at ' + configSettings . puppetDir ) ;
127+ return true ;
100128 }
101129}
102130
0 commit comments