Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Get config from workspace configuration (#247)
Browse files Browse the repository at this point in the history
Co-authored-by: Rahul Kadyan <[email protected]>
  • Loading branch information
znck and znck committed May 11, 2022
1 parent 3777cc4 commit c735bc8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-lions-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'grammarly-languageserver': patch
---

Use config from workspace configuration in Grammarly SDK
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ export class ConfigurationService implements Registerable {
}

public async getSettings(): Promise<DocumentConfig> {
return await this.#connection.workspace.getConfiguration('grammarly')
const result: { config?: DocumentConfig } | undefined = await this.#connection.workspace.getConfiguration(
'grammarly',
)

return result?.config ?? {}
}

public async getDocumentSettings(uri: string): Promise<DocumentConfig> {
return Promise.race([
const result: { config?: DocumentConfig } | undefined = await Promise.race([
this.#connection.workspace.getConfiguration({ scopeUri: uri, section: 'grammarly' }),
new Promise((resolve) => setTimeout(resolve, 1000, {})),
])

return result?.config ?? {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class DiagnosticsService implements Registerable {
this.#connection.console.log(`${document.session.status} ${document.original.uri}`)
const diagnostics = new Map<SuggestionId, SuggestionDiagnostic>()
const sendDiagnostics = (): void => {
this.#connection.console.log(`${diagnostics.size} suggestion(s) in ${document.original.uri}`)
this.#connection.sendDiagnostics({
uri: document.original.uri,
diagnostics: Array.from(diagnostics.values()).map((item) => item.diagnostic),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ export class DocumentService implements Registerable {
this.#config = config
this.#documents = createTextDocuments({
create(uri, languageId, version, content) {
return new GrammarlyDocument(TextDocument.create(uri, languageId, version, content), async () =>
sdk.withText({ ops: [] }, await config.getDocumentSettings(uri)),
)
return new GrammarlyDocument(TextDocument.create(uri, languageId, version, content), async () => {
const options = await config.getDocumentSettings(uri)
connection.console.log(`create text checking session for "${uri}" with ${JSON.stringify(options, null, 2)} `)
return sdk.withText({ ops: [] }, options)
})
},
update(document, changes, version) {
document.update(changes, version)
Expand Down

0 comments on commit c735bc8

Please sign in to comment.