11'use strict' ;
22
33import * as vscode from 'vscode' ;
4- import * as path from 'path' ;
5- import * as net from 'net' ;
6- import * as cp from 'child_process' ;
7- import ChildProcess = cp . ChildProcess ;
8- import {
9- LanguageClient , LanguageClientOptions , SettingMonitor , ServerOptions ,
10- ErrorAction , ErrorHandler , CloseAction , TransportKind , RequestType0
11- } from 'vscode-languageclient' ;
124
13- import { PuppetNodeGraphContentProvider , isNodeGraphFile , getNodeGraphUri } from '../src/providers/previewNodeGraphProvider' ;
14- import { puppetResourceCommand } from '../src/commands/puppetResourceCommand' ;
15- import { puppetModuleCommand } from '../src/commands/puppetModuleCommand' ;
16- import * as messages from '../src/messages' ;
5+ import { startLangServerTCP } from '../src/languageserver' ;
6+ import { setupPuppetCommands } from '../src/puppetcommands' ;
177
18- const langID = 'puppet' ;
8+ const langID = 'puppet' ; // don't change this
199var statusBarItem ;
20- var languageServerClient : LanguageClient = undefined ;
2110
2211export function activate ( context : vscode . ExtensionContext ) {
2312 let config = vscode . workspace . getConfiguration ( 'puppet' ) ;
@@ -30,34 +19,10 @@ export function activate(context: vscode.ExtensionContext) {
3019
3120 createStatusBarItem ( ) ;
3221
33- context . subscriptions . push ( startLangServerTCP ( host , port , langID , [ langID ] ) ) ;
22+ var languageServerClient = startLangServerTCP ( host , port , langID , statusBarItem ) ;
23+ context . subscriptions . push ( languageServerClient . start ( ) ) ;
3424
35- let resourceCommand = new puppetResourceCommand ( languageServerClient ) ;
36- context . subscriptions . push ( resourceCommand ) ;
37- context . subscriptions . push ( vscode . commands . registerCommand ( 'extension.puppetResource' , ( ) => {
38- resourceCommand . run ( ) ;
39- } ) ) ;
40-
41- let moduleCommand = new puppetModuleCommand ( ) ;
42- context . subscriptions . push ( moduleCommand ) ;
43- context . subscriptions . push ( vscode . commands . registerCommand ( 'extension.puppetModule' , ( ) => {
44- moduleCommand . listModules ( ) ;
45- } ) ) ;
46-
47- context . subscriptions . push ( vscode . commands . registerCommand (
48- 'extension.puppetShowNodeGraphToSide' ,
49- uri => showNodeGraph ( uri , true ) )
50- ) ;
51-
52- const contentProvider = new PuppetNodeGraphContentProvider ( context , languageServerClient ) ;
53- const contentProviderRegistration = vscode . workspace . registerTextDocumentContentProvider ( langID , contentProvider ) ;
54-
55- context . subscriptions . push ( vscode . workspace . onDidSaveTextDocument ( document => {
56- if ( isNodeGraphFile ( document ) ) {
57- const uri = getNodeGraphUri ( document . uri ) ;
58- contentProvider . update ( uri ) ;
59- }
60- } ) ) ;
25+ setupPuppetCommands ( langID , languageServerClient , context ) ;
6126
6227 console . log ( 'Congratulations, your extension "vscode-puppet" is now active!' ) ;
6328}
@@ -66,45 +31,11 @@ export function activate(context: vscode.ExtensionContext) {
6631export function deactivate ( ) {
6732}
6833
69- function startLangServerTCP ( host : string , port : number , langID : string , documentSelector : string | string [ ] ) : vscode . Disposable {
70- let serverOptions : ServerOptions = function ( ) {
71- return new Promise ( ( resolve , reject ) => {
72- var client = new net . Socket ( ) ;
73- client . connect ( port , host , function ( ) {
74- resolve ( { reader : client , writer : client } ) ;
75- } ) ;
76- client . on ( 'error' , function ( err ) {
77- console . log ( `[Puppet Lang Server Client] ` + err ) ;
78- } )
79- } ) ;
80- }
81-
82- let clientOptions : LanguageClientOptions = {
83- documentSelector : [ langID ] ,
84- }
85-
86- var title = `tcp lang server (host ${ host } port ${ port } )` ;
87- languageServerClient = new LanguageClient ( title , serverOptions , clientOptions )
88- languageServerClient . onReady ( ) . then ( ( ) => {
89- languageServerClient . sendRequest ( messages . PuppetVersionRequest . type ) . then ( ( versionDetails ) => {
90- statusBarItem . color = "#affc74" ;
91- statusBarItem . text = "$(terminal) " + versionDetails . puppetVersion ;
92- } ) ;
93- } , ( reason ) => {
94- this . setSessionFailure ( "Could not start language service: " , reason ) ;
95- } ) ;
96-
97- return languageServerClient . start ( ) ;
98- }
99-
10034// Status Bar handler
10135export function createStatusBarItem ( ) {
10236 if ( statusBarItem === undefined ) {
103- // Create the status bar item and place it right next
104- // to the language indicator
37+ // Create the status bar item and place it right next to the language indicator
10538 statusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right , 1 ) ;
106-
107- //this.statusBarItem.command = this.ShowSessionMenuCommandName;
10839 statusBarItem . show ( ) ;
10940 vscode . window . onDidChangeActiveTextEditor ( textEditor => {
11041 if ( textEditor === undefined || textEditor . document . languageId !== "puppet" ) {
@@ -117,40 +48,3 @@ export function createStatusBarItem() {
11748 }
11849}
11950
120- function showNodeGraph ( uri ?: vscode . Uri , sideBySide : boolean = false ) {
121- let resource = uri ;
122- if ( ! ( resource instanceof vscode . Uri ) ) {
123- if ( vscode . window . activeTextEditor ) {
124- // we are relaxed and don't check for puppet files
125- // TODO: Should we? Probably
126- resource = vscode . window . activeTextEditor . document . uri ;
127- }
128- }
129-
130- const thenable = vscode . commands . executeCommand ( 'vscode.previewHtml' ,
131- getNodeGraphUri ( resource ) ,
132- getViewColumn ( sideBySide ) ,
133- `Node Graph '${ path . basename ( resource . fsPath ) } '` ) ;
134-
135- return thenable ;
136- }
137-
138- function getViewColumn ( sideBySide : boolean ) : vscode . ViewColumn | undefined {
139- const active = vscode . window . activeTextEditor ;
140- if ( ! active ) {
141- return vscode . ViewColumn . One ;
142- }
143-
144- if ( ! sideBySide ) {
145- return active . viewColumn ;
146- }
147-
148- switch ( active . viewColumn ) {
149- case vscode . ViewColumn . One :
150- return vscode . ViewColumn . Two ;
151- case vscode . ViewColumn . Two :
152- return vscode . ViewColumn . Three ;
153- }
154-
155- return active . viewColumn ;
156- }
0 commit comments