Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed May 17, 2024
1 parent 815f4d8 commit 8920cbd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
29 changes: 11 additions & 18 deletions packages/language-server/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createConnection, TextDocuments, InitializeParams, WorkspaceFolder, Disposable, Connection, InitializedNotification } from 'vscode-languageserver/node'
import { createConnection, TextDocuments, InitializeParams, WorkspaceFolder, Disposable, Connection, InitializedNotification, DidChangeConfigurationNotification } from 'vscode-languageserver/node'
import { TextDocument } from 'vscode-languageserver-textdocument'
import path from 'node:path'
import CSSLanguageService, { Settings as CSSLanguageServiceSettings } from '@master/css-language-service'
Expand All @@ -24,7 +24,7 @@ export default class CSSLanguageServer {
workspaceFolders: WorkspaceFolder[] = []
workspaces = new Set<Workspace>()
documents: TextDocuments<TextDocument>
initializing?: Promise<any[]>
initializing?: Promise<void>
private disposables: Disposable[] = []

constructor(
Expand Down Expand Up @@ -135,26 +135,19 @@ export default class CSSLanguageServer {

init() {
if (this.initializing) return this.initializing
return this.initializing = Promise.all(
[
...this.workspaceFolders.map((folder) => this.initWorkspaceFolder(folder.uri)),
// this.connection.client.register(DidChangeConfigurationNotification.type, undefined)
]
)
// eslint-disable-next-line no-async-promise-executor
return this.initializing = new Promise(async (resolve) => {
await Promise.all(this.workspaceFolders.map((folder) => this.initWorkspaceFolder(folder.uri)))
resolve()
})
}

private async initWorkspaceFolder(workspaceFolderURI: string) {
const workspaceFolderCWD = URI.parse(workspaceFolderURI).fsPath
let customWorkspaceFolderSettings: Settings | undefined
try {
customWorkspaceFolderSettings = await this.connection.workspace.getConfiguration({
scopeUri: workspaceFolderURI,
section: 'masterCSS'
}) as Settings
} catch (error) {
console.error('Failed to load workspace folder settings', workspaceFolderURI)
console.error(error)
}
const customWorkspaceFolderSettings = await this.connection.workspace.getConfiguration({
scopeUri: workspaceFolderURI,
section: 'masterCSS'
}) as Settings
const { workspaces, ...languageServiceSettings } = extend(settings, this.customSettings, customWorkspaceFolderSettings) as Settings
const resolvedWorkspaceDirectories = new Set<string>([workspaceFolderCWD])
console.info('Registered workspace folder', workspaceFolderURI)
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/tests/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CSSLanguageServer, { Settings } from '../src'

export function connect(settings?: Settings) {
class TestStream extends Duplex {
_write(chunk: string, _encoding: BufferEncoding, done: () => void) {
_write(chunk: Buffer, _encoding: BufferEncoding, done: () => void) {
this.emit('data', chunk)
done()
}
Expand Down
6 changes: 2 additions & 4 deletions packages/language-server/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import CSSLanguageServer, { Settings } from '../src'
import { beforeAll, describe } from 'vitest'
import { resolve } from 'node:path'
import { URI } from 'vscode-uri'
import { Duplex } from 'node:stream'
import createDocument from '../src/utils/create-document'
import { connect } from './connection'

Expand Down Expand Up @@ -127,11 +126,10 @@ export function withFixture(fixture: string, cb: (context: FixtureContext) => vo
await clientConnection.sendRequest(InitializeRequest.type, {
rootUri,
capabilities,
workspaceFolders,
trace: 'verbose'
workspaceFolders
} as InitializeParams)
await clientConnection.sendNotification(InitializedNotification.method, {})
// await server.init()
await server.init()
return () => {
server.stop()
clientConnection.dispose()
Expand Down

0 comments on commit 8920cbd

Please sign in to comment.