Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ npx tailwindcss init

- `tailwindCSS.enable`: Enable coc-tailwindcss3 extension, default: `true`
- `tailwindCSS.trace.server`: Trace level of tailwindCSS language server, default: `off`
- `tailwindCSS-css-mode.trace.server`: Trace level of tailwindCSS CSS Mode language server, default: `""`
- `tailwindCSS.custom.serverPath`: Custom path to server module. If there is no setting, the built-in module will be used, default: `""`
- `tailwindCSS.custom.cssModeServerPath`: Custom path to css mode server module, default: `""`
- `tailwindCSS.emmetCompletions`: Enable class name completions when using Emmet-style syntax, for example `div.bg-red-500.uppercase`, default: `false`
- `tailwindCSS.includeLanguages`: Enable features in languages that are not supported by default. Add a mapping here between the new language and an already supported language. E.g.: `{"plaintext": "html"}`, default: `{ "eelixir": "html", "elixir": "html", "eruby": "html", "htmldjango": "html", "html.twig": "html" }`
- `tailwindCSS.files.exclude`: Configure glob patterns to exclude from all IntelliSense features. Inherits all glob patterns from the `#files.exclude#` setting, default: ["**/.git/**", "**/node_modules/**", "**/.hg/**"]
Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,26 @@
],
"description": "Trace level of tailwindCSS language server"
},
"tailwindCSS-css-mode.trace.server": {
"type": "string",
"default": "off",
"enum": [
"off",
"messages",
"verbose"
],
"description": "Trace level of tailwindCSS CSS Mode language server"
},
"tailwindCSS.custom.serverPath": {
"type": "string",
"default": "",
"description": "Custom path to server module. If there is no setting, the built-in module will be used"
},
"tailwindCSS.custom.cssModeServerPath": {
"type": "string",
"default": "",
"description": "Custom path to css mode server module."
},
"tailwindCSS.emmetCompletions": {
"type": "boolean",
"default": false,
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export function getConfigCustomServerPath() {
return workspace.getConfiguration('tailwindCSS').get<string>('custom.serverPath', '');
}

export function getConfigCustomCssModeServerPath() {
return workspace.getConfiguration('tailwindCSS').get<string>('custom.cssModeServerPath', '');
}

export function getConfigExcludePatterns(): string[] {
return workspace.getConfiguration('tailwindCSS').get<string[]>('files.exclude', []);
}
55 changes: 54 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import {
import fs from 'fs';
import minimatch from 'minimatch';
import path from 'path';
import { getConfigCustomServerPath, getConfigExcludePatterns, getConfigTailwindCssEnable } from './config';
import {
getConfigCustomCssModeServerPath,
getConfigCustomServerPath,
getConfigExcludePatterns,
getConfigTailwindCssEnable,
} from './config';
import { dedupe, equal } from './util/array';
import isObject from './util/isObject';
import { languages as defaultLanguages } from './util/languages';
Expand Down Expand Up @@ -148,6 +153,54 @@ export async function activate(context: ExtensionContext) {
})
);

let cssServerBooted = false;
async function bootCssServer() {
if (cssServerBooted) return;
cssServerBooted = true;

let module = getConfigCustomCssModeServerPath();
if (!module) return;
if (fs.existsSync(module)) {
module = module;
}

const client = new LanguageClient(
'tailwindCSS-css-mode',
'Tailwind CSS',
{
run: {
module,
transport: TransportKind.ipc,
},
debug: {
module,
transport: TransportKind.ipc,
options: {
execArgv: ['--nolazy', '--inspect=6051'],
},
},
},
{
documentSelector: [{ language: 'tailwindcss' }],
outputChannelName: 'Tailwind CSS Language Mode',
synchronize: { configurationSection: ['css'] },
}
);

context.subscriptions.push(client.start());
}

workspace.onDidOpenTextDocument(
async () => {
const { document } = await workspace.getCurrentState();
if (document.languageId === 'tailwindcss') {
bootCssServer();
}
},
null,
context.subscriptions
);

function bootWorkspaceClient(folder: WorkspaceFolder) {
if (clients.has(folder.uri.toString())) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/util/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const htmlLanguages = [
'twig',
];

export const cssLanguages = ['css', 'less', 'postcss', 'sass', 'scss', 'stylus', 'sugarss'];
export const cssLanguages = ['css', 'less', 'postcss', 'sass', 'scss', 'stylus', 'sugarss', 'tailwindcss'];

export const jsLanguages = ['javascript', 'javascriptreact', 'reason', 'rescript', 'typescript', 'typescriptreact'];

Expand Down