-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(perf): allow configuring search path #2952
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,116 +32,135 @@ connection.onInitialize((params) => { | |
connection.console.log( | ||
`[Home Assistant Language Server(${process.pid})] Started and initialize received`, | ||
); | ||
|
||
const configurationService = new ConfigurationService(); | ||
|
||
const haConnection = new HaConnection(configurationService); | ||
const fileAccessor = new VsCodeFileAccessor(params.rootUri, documents); | ||
const haConfig = new HomeAssistantConfiguration(fileAccessor); | ||
|
||
const definitionProviders = [ | ||
new IncludeDefinitionProvider(fileAccessor), | ||
new ScriptDefinitionProvider(haConfig), | ||
]; | ||
|
||
const jsonWorkerContributions = [ | ||
new EntityIdCompletionContribution(haConnection), | ||
new ServicesCompletionContribution(haConnection), | ||
]; | ||
|
||
const schemaServiceForIncludes = new SchemaServiceForIncludes(); | ||
|
||
const yamlLanguageService = getLanguageService( | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async () => "", | ||
null, | ||
jsonWorkerContributions, | ||
); | ||
|
||
const sendDiagnostics = (uri: string, diagnostics: Diagnostic[]) => { | ||
connection.sendDiagnostics({ | ||
uri, | ||
diagnostics, | ||
}); | ||
}; | ||
// Wait for configuration to be loaded before initialising the rest | ||
connection.onDidChangeConfiguration(async (config) => { | ||
connection.console.log( | ||
`[Home Assistant Language Server(${process.pid})] didChangeConfiguration received`, | ||
) | ||
configurationService.updateConfiguration(config); | ||
|
||
const discoverFilesAndUpdateSchemas = async () => { | ||
try { | ||
await haConfig.discoverFiles(); | ||
homeAsisstantLanguageService.findAndApplySchemas(); | ||
} catch (e) { | ||
console.error( | ||
`Unexpected error during file discovery / schema configuration: ${e}`, | ||
); | ||
const haConnection = new HaConnection(configurationService); | ||
console.log(`configurationService.url: ${configurationService.url}`) | ||
console.log(`configurationService.searchPath: ${configurationService.searchPath}`) | ||
console.log(`params.rootUri: ${params.rootUri}`) | ||
Comment on lines
+47
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helped a lot in understanding what was going on on startup. TODO: remove this before merge if PR is accepted. |
||
let rootUri = params.rootUri; | ||
if (configurationService.searchPath !== undefined) { | ||
rootUri = configurationService.searchPath; | ||
} | ||
}; | ||
console.log(`rootUri: ${rootUri}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helped a lot in understanding what was going on on startup. TODO: remove this before merge if PR is accepted. |
||
const fileAccessor = new VsCodeFileAccessor(rootUri, documents); | ||
const haConfig = new HomeAssistantConfiguration(fileAccessor); | ||
|
||
const definitionProviders = [ | ||
new IncludeDefinitionProvider(fileAccessor), | ||
new ScriptDefinitionProvider(haConfig), | ||
]; | ||
|
||
const jsonWorkerContributions = [ | ||
new EntityIdCompletionContribution(haConnection), | ||
new ServicesCompletionContribution(haConnection), | ||
]; | ||
|
||
const schemaServiceForIncludes = new SchemaServiceForIncludes(); | ||
|
||
const yamlLanguageService = getLanguageService( | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async () => "", | ||
null, | ||
jsonWorkerContributions, | ||
); | ||
|
||
const homeAsisstantLanguageService = new HomeAssistantLanguageService( | ||
yamlLanguageService, | ||
haConfig, | ||
haConnection, | ||
definitionProviders, | ||
schemaServiceForIncludes, | ||
sendDiagnostics, | ||
() => { | ||
documents.all().forEach(async (d) => { | ||
const diagnostics = | ||
await homeAsisstantLanguageService.getDiagnostics(d); | ||
sendDiagnostics(d.uri, diagnostics); | ||
const sendDiagnostics = (uri: string, diagnostics: Diagnostic[]) => { | ||
connection.sendDiagnostics({ | ||
uri, | ||
diagnostics, | ||
}); | ||
}, | ||
); | ||
}; | ||
|
||
const discoverFilesAndUpdateSchemas = async () => { | ||
try { | ||
await haConfig.discoverFiles(); | ||
homeAsisstantLanguageService.findAndApplySchemas(); | ||
} catch (e) { | ||
console.error( | ||
`Unexpected error during file discovery / schema configuration: ${e}`, | ||
); | ||
} | ||
}; | ||
|
||
const homeAsisstantLanguageService = new HomeAssistantLanguageService( | ||
yamlLanguageService, | ||
haConfig, | ||
haConnection, | ||
definitionProviders, | ||
schemaServiceForIncludes, | ||
sendDiagnostics, | ||
() => { | ||
documents.all().forEach(async (d) => { | ||
const diagnostics = await homeAsisstantLanguageService.getDiagnostics( | ||
d, | ||
); | ||
sendDiagnostics(d.uri, diagnostics); | ||
}); | ||
}, | ||
); | ||
|
||
documents.onDidChangeContent((e) => | ||
homeAsisstantLanguageService.onDocumentChange(e), | ||
); | ||
documents.onDidOpen((e) => homeAsisstantLanguageService.onDocumentOpen(e)); | ||
documents.onDidChangeContent((e) => | ||
homeAsisstantLanguageService.onDocumentChange(e), | ||
); | ||
documents.onDidOpen((e) => homeAsisstantLanguageService.onDocumentOpen(e)); | ||
|
||
let onDidSaveDebounce: NodeJS.Timer; | ||
documents.onDidSave(() => { | ||
clearTimeout(onDidSaveDebounce); | ||
onDidSaveDebounce = setTimeout(discoverFilesAndUpdateSchemas, 100); | ||
}); | ||
let onDidSaveDebounce: NodeJS.Timer; | ||
documents.onDidSave(() => { | ||
clearTimeout(onDidSaveDebounce); | ||
onDidSaveDebounce = setTimeout(discoverFilesAndUpdateSchemas, 100); | ||
}); | ||
|
||
connection.onDocumentSymbol((p) => | ||
homeAsisstantLanguageService.onDocumentSymbol( | ||
documents.get(p.textDocument.uri), | ||
), | ||
); | ||
connection.onDocumentFormatting((p) => | ||
homeAsisstantLanguageService.onDocumentFormatting( | ||
documents.get(p.textDocument.uri), | ||
p.options, | ||
), | ||
); | ||
connection.onCompletion((p) => | ||
homeAsisstantLanguageService.onCompletion( | ||
documents.get(p.textDocument.uri), | ||
p.position, | ||
), | ||
); | ||
connection.onCompletionResolve((p) => | ||
homeAsisstantLanguageService.onCompletionResolve(p), | ||
); | ||
connection.onHover((p) => | ||
homeAsisstantLanguageService.onHover( | ||
documents.get(p.textDocument.uri), | ||
p.position, | ||
), | ||
); | ||
connection.onDefinition((p) => | ||
homeAsisstantLanguageService.onDefinition( | ||
documents.get(p.textDocument.uri), | ||
p.position, | ||
), | ||
); | ||
connection.onDocumentSymbol((p) => | ||
homeAsisstantLanguageService.onDocumentSymbol( | ||
documents.get(p.textDocument.uri), | ||
), | ||
); | ||
connection.onDocumentFormatting((p) => | ||
homeAsisstantLanguageService.onDocumentFormatting( | ||
documents.get(p.textDocument.uri), | ||
p.options, | ||
), | ||
); | ||
connection.onCompletion((p) => | ||
homeAsisstantLanguageService.onCompletion( | ||
documents.get(p.textDocument.uri), | ||
p.position, | ||
), | ||
); | ||
connection.onCompletionResolve((p) => | ||
homeAsisstantLanguageService.onCompletionResolve(p), | ||
); | ||
connection.onHover((p) => | ||
homeAsisstantLanguageService.onHover( | ||
documents.get(p.textDocument.uri), | ||
p.position, | ||
), | ||
); | ||
connection.onDefinition((p) => | ||
homeAsisstantLanguageService.onDefinition( | ||
documents.get(p.textDocument.uri), | ||
p.position, | ||
), | ||
); | ||
|
||
connection.onDidChangeConfiguration(async (config) => { | ||
configurationService.updateConfiguration(config); | ||
await haConnection.notifyConfigUpdate(); | ||
|
||
if (!configurationService.isConfigured) { | ||
connection.sendNotification("no-config"); | ||
} | ||
|
||
// fire and forget | ||
setTimeout(discoverFilesAndUpdateSchemas, 0); | ||
}); | ||
|
||
connection.onRequest( | ||
|
@@ -179,9 +198,6 @@ connection.onInitialize((params) => { | |
connection.sendNotification("render_template_completed", outputString); | ||
}); | ||
|
||
// fire and forget | ||
setTimeout(discoverFilesAndUpdateSchemas, 0); | ||
|
||
return { | ||
capabilities: <ServerCapabilities>{ | ||
textDocumentSync: TextDocumentSyncKind.Full, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helped a lot in understanding what was going on on startup.
TODO: remove this before merge if PR is accepted.