Skip to content

Use one server to handle all folders in a workspace #957

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 9 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Run prettier
  • Loading branch information
thecrypticace committed Apr 24, 2024
commit 1cb121e3dc16faf95ecf7ec8689c871aa35fb864
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let connection = createConnection(ProposedFeatures.all)
interceptLogs(console, connection)

process.on('unhandledRejection', (e: any) => {
console.error("Unhandled exception", e)
console.error('Unhandled exception', e)
})

let documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument)
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export class TW {
(patterns: string[]) => watchPatterns(patterns),
tailwindVersion,
this.settingsCache.get,
userLanguages
userLanguages,
)
this.projects.set(key, project)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"workspaces": ["packages/*"],
"workspaces": [
"packages/*"
],
"dependencies": {
"tailwindcss": "^4.0.0-alpha.12"
}
Expand Down
28 changes: 15 additions & 13 deletions packages/vscode-tailwindcss/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
Range,
RelativePattern,
} from 'vscode'
import type { DocumentFilter, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node'
import type {
DocumentFilter,
LanguageClientOptions,
ServerOptions,
} from 'vscode-languageclient/node'
import {
LanguageClient,
TransportKind,
Expand Down Expand Up @@ -295,7 +299,6 @@ export async function activate(context: ExtensionContext) {
let needsReboot = folders.some((folder) => {
return (
event.affectsConfiguration('tailwindCSS.experimental.configFile', folder) ||

// TODO: Only reboot if the MAPPING changed instead of just the languages
// e.g. "plaintext" already exists but you change it from "html" to "css"
// TODO: This should not cause a reboot of the server but should instead
Expand Down Expand Up @@ -383,8 +386,11 @@ export async function activate(context: ExtensionContext) {
module = context.asAbsolutePath(prod)
} catch (_) {}

let workspaceFile = Workspace.workspaceFile?.scheme === 'file' ? Workspace.workspaceFile : undefined
let inspectPort = Workspace.getConfiguration('tailwindCSS', workspaceFile).get<number | null>('inspectPort') ?? null
let workspaceFile =
Workspace.workspaceFile?.scheme === 'file' ? Workspace.workspaceFile : undefined
let inspectPort =
Workspace.getConfiguration('tailwindCSS', workspaceFile).get<number | null>('inspectPort') ??
null

let serverOptions: ServerOptions = {
run: {
Expand Down Expand Up @@ -419,11 +425,7 @@ export async function activate(context: ExtensionContext) {
let selections = editor.selections
let edits = result.additionalTextEdits || []

if (
selections.length <= 1 ||
edits.length === 0 ||
result['data'] !== 'variant'
) {
if (selections.length <= 1 || edits.length === 0 || result['data'] !== 'variant') {
return result
}

Expand Down Expand Up @@ -491,9 +493,7 @@ export async function activate(context: ExtensionContext) {
workspace: {
configuration: (params) => {
return params.items.map(({ section, scopeUri }) => {
let scope: ConfigurationScope | null = scopeUri
? Uri.parse(scopeUri)
: null
let scope: ConfigurationScope | null = scopeUri ? Uri.parse(scopeUri) : null

let settings = Workspace.getConfiguration(section, scope)

Expand Down Expand Up @@ -564,7 +564,9 @@ export async function activate(context: ExtensionContext) {
await bootWorkspaceClient()
}

async function anyFolderNeedsLanguageServer(folders: readonly WorkspaceFolder[]): Promise<boolean> {
async function anyFolderNeedsLanguageServer(
folders: readonly WorkspaceFolder[],
): Promise<boolean> {
for (let folder of folders) {
if (await folderNeedsLanguageServer(folder)) {
return true
Expand Down