tailwindlabs / tailwindcss-intellisense

Intelligent Tailwind CSS tooling for Visual Studio Code
2.74k stars 183 forks source link

tailwindCSS.experimental.configFile using wrong base path, when set as relative path in project opened as vscode code-workspace #948

Closed maxnrm closed 2 months ago

maxnrm commented 3 months ago

What version of VS Code are you using?

VSCode version: 1.87.2

What version of Tailwind CSS IntelliSense are you using?

Tailwind CSS IntelliSense version: v0.10.5

What version of Tailwind CSS are you using?

TailwindCSS version: v3.4.1

What package manager are you using?

No JS package manager, I use Go

What operating system are you using?

OS: Manjaro Linux

Tailwind config

/** @type {import('tailwindcss').config} */
export default {
  darkMode: 'class',
  content: ['./web/templates/*.templ'],
  theme: {
    extend: {
      colors: {
        primary: { "50": "#eff6ff", "100": "#dbeafe", "200": "#bfdbfe", "300": "#93c5fd", "400": "#60a5fa", "500": "#3b82f6", "600": "#2563eb", "700": "#1d4ed8", "800": "#1e40af", "900": "#1e3a8a", "950": "#172554" }
      }
    },
    fontFamily: {
      'body': [
        'Inter',
        'ui-sans-serif',
        'system-ui',
        '-apple-system',
        'system-ui',
        'Segoe UI',
        'Roboto',
        'Helvetica Neue',
        'Arial',
        'Noto Sans',
        'sans-serif',
        'Apple Color Emoji',
        'Segoe UI Emoji',
        'Segoe UI Symbol',
        'Noto Color Emoji'
      ],
      'sans': [
        'Inter',
        'ui-sans-serif',
        'system-ui',
        '-apple-system',
        'system-ui',
        'Segoe UI',
        'Roboto',
        'Helvetica Neue',
        'Arial',
        'Noto Sans',
        'sans-serif',
        'Apple Color Emoji',
        'Segoe UI Emoji',
        'Segoe UI Symbol',
        'Noto Color Emoji'
      ]
    }
  }
}

VS Code settings

{
    "explorer.confirmDelete": false,
    "workbench.colorTheme": "Solarized Light",
    "debug.console.fontSize": 18,
    "chat.editor.fontSize": 18,
    "terminal.external.linuxExec": "alacritty",
    "terminal.integrated.fontFamily": "'Droid Sans Mono', 'monospace', monospace",
    "git.confirmSync": false,
    "explorer.confirmDragAndDrop": false,
    "editor.unicodeHighlight.allowedLocales": {
        "ru": true
    },
    "git.openRepositoryInParentFolders": "never",
    "http.proxyStrictSSL": false,
    "http.proxySupport": "on",
    "vs-kubernetes": {
        "vs-kubernetes.crd-code-completion": "disabled"
    },
    "go.toolsManagement.autoUpdate": true,
    "http.proxy": "http://127.0.0.1:10809",
    "github.copilot.enable": {
        "*": true,
        "plaintext": false,
        "markdown": false,
        "scminput": false
    },
    "editor.wordWrap": "on",
    "extensions.ignoreRecommendations": true,
    "editor.lineNumbers": "relative",
    "tailwindCSS.emmetCompletions": true,
    "tailwindCSS.includeLanguages": {
        "templ": "html"
    },
    "tailwindCSS.experimental.configFile": "config/tailwind/tailwind.config.js",
}

Reproduction URL

Just open any project from VSCode code-workspace file and set tailwindCSS.experimental.configFile

Describe your issue

When tailwindCSS.experimental.configFile is set in a project, that was open from VSCode code-workspace and it is relative path, it is using base path of code-workspace file, and I presume a correct behaviour would be to use path to project folder as base path.

Error: ENOENT: no such file or directory, stat '/home/maxnrm/delo/code_workspaces/config/tailwind/tailwind.config.js'
    at statSync (node:fs:1692:3)
    at Object.<anonymous> (node:electron/js2c/node_init:2:4795)
    at /home/maxnrm/.vscode/extensions/bradlc.vscode-tailwindcss-0.10.5/dist/tailwindServer.js:2950:444
    at Array.map (<anonymous>)
    at fHe (/home/maxnrm/.vscode/extensions/bradlc.vscode-tailwindcss-0.10.5/dist/tailwindServer.js:2950:431)
    at P (/home/maxnrm/.vscode/extensions/bradlc.vscode-tailwindcss-0.10.5/dist/tailwindServer.js:2950:4942)
    at Object.I [as tryInit] (/home/maxnrm/.vscode/extensions/bradlc.vscode-tailwindcss-0.10.5/dist/tailwindServer.js:2950:4422)
    at KR._init (/home/maxnrm/.vscode/extensions/bradlc.vscode-tailwindcss-0.10.5/dist/tailwindServer.js:2952:13103)
    at async KR.init (/home/maxnrm/.vscode/extensions/bradlc.vscode-tailwindcss-0.10.5/dist/tailwindServer.js:2952:7846)
    at async /home/maxnrm/.vscode/extensions/bradlc.vscode-tailwindcss-0.10.5/dist/tailwindServer.js:2954:1156

I think possible problem cause is here: https://github.com/tailwindlabs/tailwindcss-intellisense/blob/daa8bb2821af9cffd4d3a0e2c5982aeea0e2bd7e/packages/tailwindcss-language-server/src/tw.ts#L136

workspaceFolder which contains actual path to project folder, that workspace is opening, probably should be used instead path.dirname(workspaceFile), but I don't have enough understanding of VSCode extensions nor this package internals to create a proper PR.

Temporary solution could be to use aboslute path to config, which I do for now.

Thanks in advance.

thecrypticace commented 2 months ago

@maxnrm Can you provide a repro that showcases your project structure including the VSCode workspace setup and Tailwind CSS config file(s)?

If you have a workspace file open the path is relative to that file — which is definitely intentional — because that's the file you specify the settings in. Per-folder overrides are not (yet) supported for tailwindCSS.experimental.configFile and VSCode will warn you about this:

Screenshot 2024-04-16 at 10 47 01
maxnrm commented 2 months ago

That's interesting. I guess the problem is that I store workspace files in separate directory from actual project folder. Thanks.