Skip to content

Commit

Permalink
Fix(VSCode): URI paths are inconsistent on Windows OS
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed May 8, 2024
1 parent 69c1ac4 commit ad4612b
Show file tree
Hide file tree
Showing 3 changed files with 3,422 additions and 198 deletions.
3 changes: 2 additions & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"fast-glob": "^3.3.2",
"js-beautify": "^1.15.1",
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-textdocument": "^1.0.11"
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-uri": "^3.0.8"
},
"devDependencies": {
"@master/css-shared": "workspace:^"
Expand Down
21 changes: 8 additions & 13 deletions packages/language-server/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createConnection, TextDocuments, InitializeParams, DidChangeConfigurationNotification, WorkspaceFolder, Disposable, Connection, ExecuteCommandRequest } from 'vscode-languageserver/node'
import { TextDocument } from 'vscode-languageserver-textdocument'
import path, { relative } from 'path'
import { fileURLToPath, pathToFileURL } from 'url'
import path from 'path'
import CSSLanguageService, { Settings as CSSLanguageServiceSettings } from '@master/css-language-service'
import { Settings } from './settings'
import exploreConfig from '@master/css-explore-config'
Expand All @@ -11,7 +10,7 @@ import { Config } from '@master/css'
import { SERVER_CAPABILITIES } from '@master/css-language-service'
import interceptLogs from './utils/intercept-logs'
import glob from 'fast-glob'
import { existsSync } from 'fs'
import { URI } from 'vscode-uri'

declare type Workspace = {
path: string
Expand Down Expand Up @@ -139,15 +138,15 @@ export default class CSSLanguageServer {
}

private async initWorkspaceFolder(workspaceFolderURI: string) {
const workspaceFolderCWD = this.fileURLToPath(workspaceFolderURI)
const workspaceFolderCWD = URI.parse(workspaceFolderURI).fsPath
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')
console.log(workspaceFolderCWD)
console.log(workspaceFolderURI)
if (workspaces === 'auto') {
(await glob('**/master.css.*', {
cwd: workspaceFolderCWD,
Expand All @@ -167,10 +166,10 @@ export default class CSSLanguageServer {
}
resolvedWorkspaceDirectories.forEach(async (workspaceDir) => {
console.info('Added workspace')
console.log(workspaceDir)
console.log(URI.file(workspaceDir).toString())
this.workspaces.add({
path: workspaceDir,
uri: pathToFileURL(workspaceDir).href,
uri: URI.file(workspaceDir).toString(),
openedTextDocuments: new Set<TextDocument>(),
languageServiceSettings
})
Expand All @@ -189,20 +188,16 @@ export default class CSSLanguageServer {
console.error(e)
}
console.info('Initialized workspace', workspaceConfig ? '(with config file)' : '')
console.log(workspace.path)
console.log(workspace.uri)
workspace.cssLanguageService = new CSSLanguageService({ ...workspace.languageServiceSettings, config: workspaceConfig })
}

destroyCSSLanguageService(workspace: Workspace) {
console.info('Destroyed workspace')
console.log(workspace.path)
console.log(workspace.uri)
delete workspace.cssLanguageService
}

fileURLToPath(workspaceURI: string) {
return fileURLToPath(workspaceURI.replace('%3A', ':'))
}

findClosestWorkspace(textDocumentURI: string) {
let foundWorkspace: Workspace | undefined
for (const workspace of this.workspaces) {
Expand Down
Loading

0 comments on commit ad4612b

Please sign in to comment.