@@ -40,7 +40,7 @@ import { registerCustomMethods } from "./custom";
4040import { isWindows , LspConnection } from "core-node" ;
4141import { initQuartoContext , Document , markdownitParser , LspInitializationOptions } from "quarto-core" ;
4242import { ConfigurationManager , lsConfiguration } from "./config" ;
43- import { LogFunctionLogger } from "./logging" ;
43+ import { Logger } from "./logging" ;
4444import { languageServiceWorkspace } from "./workspace" ;
4545import { middlewareCapabilities , middlewareRegister } from "./middleware" ;
4646import { createLanguageService , IMdLanguageService } from "./service" ;
@@ -52,12 +52,15 @@ import { registerDiagnostics } from "./diagnostics";
5252// Also include all preview / proposed LSP features.
5353const connection = createConnection ( ProposedFeatures . all ) ;
5454
55+ // Initialize logger
56+ const logger = new Logger ( console . log . bind ( console ) ) ;
57+
5558// Create text document manager
5659const documents : TextDocuments < Document > = new TextDocuments ( TextDocument ) ;
5760documents . listen ( connection ) ;
5861
5962// Configuration
60- const configManager = new ConfigurationManager ( connection ) ;
63+ const configManager = new ConfigurationManager ( connection , logger ) ;
6164const config = lsConfiguration ( configManager ) ;
6265
6366// Capabilities
@@ -66,16 +69,29 @@ let capabilities: ClientCapabilities | undefined;
6669// Initialization options
6770let initializationOptions : LspInitializationOptions | undefined ;
6871
69- // Markdowdn language service
72+ // Markdown language service
7073let mdLs : IMdLanguageService | undefined ;
7174
7275connection . onInitialize ( ( params : InitializeParams ) => {
76+ // Set log level from initialization options if provided so that we use the
77+ // expected level as soon as possible
78+ const initLogLevel = Logger . parseLogLevel (
79+ params . initializationOptions ?. logLevel ?? "warn"
80+ ) ;
81+ logger . init ( initLogLevel ) ;
82+ configManager . init ( initLogLevel ) ;
83+
84+ // We're connected, log messages via LSP
85+ logger . setConnection ( connection ) ;
86+ logger . logRequest ( 'initialize' ) ;
7387
7488 // alias options and capabilities
7589 initializationOptions = params . initializationOptions ;
7690 capabilities = params . capabilities ;
7791
7892 connection . onCompletion ( async ( params , token ) : Promise < CompletionItem [ ] > => {
93+ logger . logRequest ( 'completion' ) ;
94+
7995 const document = documents . get ( params . textDocument . uri ) ;
8096 if ( ! document ) {
8197 return [ ] ;
@@ -85,6 +101,8 @@ connection.onInitialize((params: InitializeParams) => {
85101 } )
86102
87103 connection . onHover ( async ( params , token ) : Promise < Hover | null | undefined > => {
104+ logger . logRequest ( 'hover' ) ;
105+
88106 const document = documents . get ( params . textDocument . uri ) ;
89107 if ( ! document ) {
90108 return null ;
@@ -94,6 +112,8 @@ connection.onInitialize((params: InitializeParams) => {
94112
95113
96114 connection . onDocumentLinks ( async ( params , token ) : Promise < DocumentLink [ ] > => {
115+ logger . logRequest ( 'documentLinks' ) ;
116+
97117 const document = documents . get ( params . textDocument . uri ) ;
98118 if ( ! document ) {
99119 return [ ] ;
@@ -102,10 +122,13 @@ connection.onInitialize((params: InitializeParams) => {
102122 } ) ;
103123
104124 connection . onDocumentLinkResolve ( async ( link , token ) : Promise < DocumentLink | undefined > => {
125+ logger . logRequest ( 'documentLinksResolve' ) ;
105126 return mdLs ?. resolveDocumentLink ( link , token ) ;
106127 } ) ;
107128
108129 connection . onDocumentSymbol ( async ( params , token ) : Promise < DocumentSymbol [ ] > => {
130+ logger . logRequest ( 'documentSymbol' ) ;
131+
109132 const document = documents . get ( params . textDocument . uri ) ;
110133 if ( ! document ) {
111134 return [ ] ;
@@ -114,6 +137,8 @@ connection.onInitialize((params: InitializeParams) => {
114137 } ) ;
115138
116139 connection . onFoldingRanges ( async ( params , token ) : Promise < FoldingRange [ ] > => {
140+ logger . logRequest ( 'foldingRanges' ) ;
141+
117142 const document = documents . get ( params . textDocument . uri ) ;
118143 if ( ! document ) {
119144 return [ ] ;
@@ -122,6 +147,8 @@ connection.onInitialize((params: InitializeParams) => {
122147 } ) ;
123148
124149 connection . onSelectionRanges ( async ( params , token ) : Promise < SelectionRange [ ] | undefined > => {
150+ logger . logRequest ( 'selectionRanges' ) ;
151+
125152 const document = documents . get ( params . textDocument . uri ) ;
126153 if ( ! document ) {
127154 return [ ] ;
@@ -130,10 +157,13 @@ connection.onInitialize((params: InitializeParams) => {
130157 } ) ;
131158
132159 connection . onWorkspaceSymbol ( async ( params , token ) : Promise < WorkspaceSymbol [ ] > => {
160+ logger . logRequest ( 'workspaceSymbol' ) ;
133161 return mdLs ?. getWorkspaceSymbols ( params . query , token ) || [ ] ;
134162 } ) ;
135163
136164 connection . onReferences ( async ( params , token ) : Promise < Location [ ] > => {
165+ logger . logRequest ( 'references' ) ;
166+
137167 const document = documents . get ( params . textDocument . uri ) ;
138168 if ( ! document ) {
139169 return [ ] ;
@@ -142,6 +172,8 @@ connection.onInitialize((params: InitializeParams) => {
142172 } ) ;
143173
144174 connection . onDefinition ( async ( params , token ) : Promise < Definition | undefined > => {
175+ logger . logRequest ( 'definition' ) ;
176+
145177 const document = documents . get ( params . textDocument . uri ) ;
146178 if ( ! document ) {
147179 return undefined ;
@@ -182,10 +214,12 @@ connection.onInitialize((params: InitializeParams) => {
182214
183215// further config dependent initialization
184216connection . onInitialized ( async ( ) => {
217+ logger . logNotification ( 'initialized' ) ;
185218
186219 // sync config if possible
187220 if ( capabilities ?. workspace ?. configuration ) {
188221 await configManager . subscribe ( ) ;
222+ logger . setConfigurationManager ( configManager ) ;
189223 }
190224
191225 // initialize connection to quarto
@@ -207,12 +241,6 @@ connection.onInitialized(async () => {
207241 ) ;
208242 const quarto = await initializeQuarto ( quartoContext ) ;
209243
210- // initialize logger
211- const logger = new LogFunctionLogger (
212- console . log . bind ( console ) ,
213- configManager
214- ) ;
215-
216244 // initialize workspace
217245 const workspace = languageServiceWorkspace (
218246 workspaceFolders ?. map ( value => URI . parse ( value . uri ) ) || [ ] ,
@@ -255,7 +283,6 @@ connection.onInitialized(async () => {
255283
256284 // register custom methods
257285 registerCustomMethods ( quarto , lspConnection , documents ) ;
258-
259286} ) ;
260287
261288
0 commit comments