Skip to content

Boot language servers for nested workspace folders #642

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

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 33 additions & 18 deletions packages/vscode-tailwindcss/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ function sortedWorkspaceFolders(): string[] {
return _sortedWorkspaceFolders
}

function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder {
let sorted = sortedWorkspaceFolders()
for (let element of sorted) {
let uri = folder.uri.toString()
if (uri.charAt(uri.length - 1) !== '/') {
uri = uri + '/'
}
if (uri.startsWith(element)) {
return Workspace.getWorkspaceFolder(Uri.parse(element))!
}
}
return folder
}

function getUserLanguages(folder?: WorkspaceFolder): Record<string, string> {
const langs = Workspace.getConfiguration('tailwindCSS', folder).includeLanguages
return isObject(langs) ? langs : {}
Expand Down Expand Up @@ -217,7 +203,6 @@ export async function activate(context: ExtensionContext) {
if (!folder || isExcluded(uri.fsPath, folder)) {
return
}
folder = getOuterMostWorkspaceFolder(folder)
bootWorkspaceClient(folder)
})

Expand All @@ -231,7 +216,6 @@ export async function activate(context: ExtensionContext) {
return
}
if (await fileContainsAtConfig(uri)) {
folder = getOuterMostWorkspaceFolder(folder)
bootWorkspaceClient(folder)
}
}
Expand Down Expand Up @@ -465,6 +449,34 @@ export async function activate(context: ExtensionContext) {
outputChannel: outputChannel,
revealOutputChannelOn: RevealOutputChannelOn.Never,
middleware: {
provideCompletionItem(document, position, context, token, next) {
let workspaceFolder = Workspace.getWorkspaceFolder(document.uri)
if (workspaceFolder !== folder) {
return null
}
return next(document, position, context, token)
},
provideHover(document, position, token, next) {
let workspaceFolder = Workspace.getWorkspaceFolder(document.uri)
if (workspaceFolder !== folder) {
return null
}
return next(document, position, token)
},
handleDiagnostics(uri, diagnostics, next) {
let workspaceFolder = Workspace.getWorkspaceFolder(uri)
if (workspaceFolder !== folder) {
return
}
next(uri, diagnostics)
},
provideCodeActions(document, range, context, token, next) {
let workspaceFolder = Workspace.getWorkspaceFolder(document.uri)
if (workspaceFolder !== folder) {
return null
}
return next(document, range, context, token)
},
async resolveCompletionItem(item, token, next) {
let result = await next(item, token)
let selections = Window.activeTextEditor.selections
Expand Down Expand Up @@ -506,6 +518,11 @@ export async function activate(context: ExtensionContext) {
return result
},
async provideDocumentColors(document, token, next) {
let workspaceFolder = Workspace.getWorkspaceFolder(document.uri)
if (workspaceFolder !== folder) {
return null
}

let colors = await next(document, token)
let editableColors = colors.filter((color) => {
let text =
Expand Down Expand Up @@ -666,8 +683,6 @@ export async function activate(context: ExtensionContext) {
if (!folder) {
return
}
// If we have nested workspace folders we only start a server on the outer most workspace folder.
folder = getOuterMostWorkspaceFolder(folder)

if (searchedFolders.has(folder.uri.toString())) {
return
Expand Down