-
-
Notifications
You must be signed in to change notification settings - Fork 475
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
🐛 Biome LSP is treating typescript files as if they were javascript files #3839
Comments
The problem was my neovim config. I removed the The fix was: lsp_zero.extend_lspconfig({
sign_text = true,
-- lsp_attach = lsp_attach, <-- remove this line
capabilities = require('cmp_nvim_lsp').default_capabilities(),
}) UPDATE: ignore this comment, the issue went away temporarily, but it seems to be intermittent. |
scratch my last comment. the issue is still happening, it's just intermittent |
Can you post your biome config? And does biome still treat it as jsx instead of tsx from the CLI? |
hi @dyc3 ! thanks for taking a look. here's our biome config: {
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto"
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"a11y": {
"noAccessKey": "error",
"noAriaUnsupportedElements": "error",
"noAutofocus": "error",
"noBlankTarget": "error",
"noDistractingElements": "error",
"noHeaderScope": "error",
"noInteractiveElementToNoninteractiveRole": "error",
"noNoninteractiveElementToInteractiveRole": "error",
"noNoninteractiveTabindex": "error",
"noPositiveTabindex": "error",
"noRedundantAlt": "error",
"noRedundantRoles": "error",
"useAltText": "error",
"useAnchorContent": "error",
"useAriaActivedescendantWithTabindex": "error",
"useAriaPropsForRole": "error",
"useButtonType": "error",
"useHeadingContent": "error",
"useHtmlLang": "error",
"useIframeTitle": "error",
"useKeyWithClickEvents": "error",
"useKeyWithMouseEvents": "error",
"useMediaCaption": "error",
"useValidAnchor": "error",
"useValidAriaProps": "error",
"useValidAriaRole": {
"level": "error",
"options": { "allowInvalidRoles": [], "ignoreNonDom": false }
},
"useValidAriaValues": "error",
"useValidLang": "error"
},
"complexity": {
"noBannedTypes": "error",
"noExtraBooleanCast": "error",
"noMultipleSpacesInRegularExpressionLiterals": "error",
"noUselessCatch": "error",
"noUselessConstructor": "error",
"noUselessFragments": "error",
"noUselessLabel": "error",
"noUselessLoneBlockStatements": "error",
"noUselessRename": "error",
"noUselessTernary": "error",
"noUselessThisAlias": "error",
"noUselessTypeConstraint": "error",
"noVoid": "error",
"noWith": "error",
"useArrowFunction": "off",
"useLiteralKeys": "error",
"useRegexLiterals": "error"
},
"correctness": {
"noChildrenProp": "error",
"noConstAssign": "error",
"noConstantCondition": "warn",
"noConstructorReturn": "error",
"noEmptyCharacterClassInRegex": "error",
"noEmptyPattern": "error",
"noGlobalObjectCalls": "error",
"noInnerDeclarations": "error",
"noInvalidConstructorSuper": "error",
"noInvalidUseBeforeDeclaration": "error",
"noNewSymbol": "error",
"noNodejsModules": "off",
"noNonoctalDecimalEscape": "error",
"noPrecisionLoss": "error",
"noSelfAssign": "error",
"noSetterReturn": "error",
"noSwitchDeclarations": "error",
"noUndeclaredVariables": "error",
"noUnreachable": "error",
"noUnreachableSuper": "error",
"noUnsafeFinally": "error",
"noUnsafeOptionalChaining": "error",
"noUnusedLabels": "error",
"noUnusedPrivateClassMembers": "off",
"noUnusedVariables": "error",
"noVoidElementsWithChildren": "error",
"useArrayLiterals": "off",
"useExhaustiveDependencies": "error",
"useIsNan": "error",
"useJsxKeyInIterable": "error",
"useValidForDirection": "error",
"useYield": "error"
},
"security": {
"noDangerouslySetInnerHtml": "warn",
"noDangerouslySetInnerHtmlWithChildren": "error",
"noGlobalEval": "error"
},
"style": {
"noArguments": "error",
"noCommaOperator": "error",
"noDefaultExport": "off",
"noImplicitBoolean": "error",
"noNamespace": "error",
"noNegationElse": "off",
"noParameterAssign": "error",
"noRestrictedGlobals": {
"level": "error",
"options": {
"deniedGlobals": [
"isFinite",
"isNaN",
"addEventListener",
"blur",
"close",
"closed",
"confirm",
"defaultStatus",
"defaultstatus",
"event",
"external",
"find",
"focus",
"frameElement",
"frames",
"history",
"innerHeight",
"innerWidth",
"length",
"location",
"locationbar",
"menubar",
"moveBy",
"moveTo",
"name",
"onblur",
"onerror",
"onfocus",
"onload",
"onresize",
"onunload",
"open",
"opener",
"opera",
"outerHeight",
"outerWidth",
"pageXOffset",
"pageYOffset",
"parent",
"print",
"removeEventListener",
"resizeBy",
"resizeTo",
"screen",
"screenLeft",
"screenTop",
"screenX",
"screenY",
"scroll",
"scrollbars",
"scrollBy",
"scrollTo",
"scrollX",
"scrollY",
"self",
"status",
"statusbar",
"stop",
"toolbar",
"top"
]
}
},
"noUselessElse": "error",
"noVar": "error",
"useAsConstAssertion": "error",
"useBlockStatements": "error",
"useCollapsedElseIf": "error",
"useConst": "error",
"useDefaultParameterLast": "error",
"useExponentiationOperator": "error",
"useFragmentSyntax": "error",
"useImportType": "error",
"useNumericLiterals": "error",
"useShorthandAssign": "error",
"useSingleVarDeclarator": "error",
"useTemplate": "error"
},
"suspicious": {
"noArrayIndexKey": "error",
"noAssignInExpressions": "error",
"noAsyncPromiseExecutor": "error",
"noCatchAssign": "error",
"noClassAssign": "error",
"noCommentText": "error",
"noCompareNegZero": "error",
"noConfusingLabels": "error",
"noConsoleLog": "warn",
"noControlCharactersInRegex": "error",
"noDebugger": "error",
"noDoubleEquals": "error",
"noDuplicateCase": "error",
"noDuplicateClassMembers": "error",
"noDuplicateJsxProps": "error",
"noDuplicateObjectKeys": "error",
"noDuplicateParameters": "error",
"noEmptyBlockStatements": "error",
"noExplicitAny": "error",
"noExtraNonNullAssertion": "error",
"noFallthroughSwitchClause": "error",
"noFunctionAssign": "error",
"noGlobalAssign": "error",
"noImportAssign": "error",
"noLabelVar": "error",
"noMisleadingCharacterClass": "error",
"noMisleadingInstantiator": "error",
"noPrototypeBuiltins": "error",
"noRedeclare": "error",
"noSelfCompare": "error",
"noShadowRestrictedNames": "error",
"noUnsafeDeclarationMerging": "error",
"noUnsafeNegation": "error",
"useAwait": "off",
"useDefaultSwitchClauseLast": "error",
"useGetterReturn": "error",
"useValidTypeof": "error"
}
},
"ignore": [
"**/node_modules/**",
"**/dist/**",
"**/storybook-static/**",
"**/.next/**"
]
},
"javascript": {
"globals": ["describe", "it"],
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "none",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
},
"overrides": [
{ "include": ["*.json"], "formatter": { "indentWidth": 2 } },
{
"include": ["*.test.ts*"],
"javascript": {
"globals": ["it", "describe"]
}
}
],
"files": {
"ignore": [
"**/node_modules/**",
"**/dist/**",
"**/storybook-static/**",
"**/.next/**",
"apps/web/src/migrations/**",
"**/importMap.js",
"**/payload-types.ts"
]
}
} This is what we got from an |
And no, when i run |
It could be your IDE is reporting the file incorrectly. I'm pretty sure this is what the LSP uses to determine the language: biome/crates/biome_js_syntax/src/file_source.rs Lines 320 to 326 in 83e5cef
Edit: Yeah I'm pretty sure this is it. Biome handles the language id correctly. |
I'm in Is there anything different about how filetypes are derived with the biome LSP compared to the eslint LSP? |
I'm not sure tbh. I'm still not super familiar with how the LSP works. You mentioned that it was intermittent: It could be there's some race condition somewhere. I'm assuming that you checked the filetype while the bug was happening? |
It must be something like that, but I don't know how to go about testing for the race condition. Neovim was reporting the correct filetype while the error was present. I tried running Also if it was a race condition, I would imagine that subsequent requests to the LSP would communicate the correct filetype, but the biome logs continue to show the filetype as |
@Conaclos i saw that a release just went up with added debugging output. Here is a log capture of this issue happening with the latest version that just went out (
Also here's a screenshot of my editor while the issue is present: |
Ok now we at least know it's not using the language id to determine the language. I forgot to put the returned values in the new logs, but just from this it seems like I won't be able to take a closer look for a while. |
I think I know the source for the problem, but not what causes it. The LSP only calls biome/crates/biome_service/src/workspace/server.rs Lines 115 to 121 in 9261b75
Something is happening that is causing these 2 fields on the biome/crates/biome_service/src/workspace/server.rs Lines 49 to 50 in 9261b75
biome/crates/biome_service/src/workspace/server.rs Lines 55 to 56 in 9261b75
I imagine it hasn't come up before if the neovim LSP client sends requests in a different order than the VSCode LSP client. |
I'll see about getting a new nightly released with the adjusted debug logs. If you could get |
Thank you @dyc3 ! I'll test as soon as the build goes up. |
Sorry for the delay @dyc3 . Just updated to
|
@dyc3 hey just making sure you saw my last comment |
Thanks, this slipped through the cracks. |
Honestly, I'm a bit stumped with this one. I think it would be easier if I could reproduce it on my own machine. I've never used neovim before, is the config you posted above sufficient for me to use? Also, could you narrow down the steps required to reproduce? |
I can consistently reproduce the problem by opening up a next.js monorepo project and then opening 2 or 3 typescript files. The first one is usually ok, but after the 2nd or 3rd file, each new file is classified as a @dyc3 my entire neovim config is up here. i think this file is the only one needed to reproduce, but it gets loaded by this file along with some other basic config. My config might not be the best starting point for nvim. You might be better off using a pre-built config like LazyVim LunarVim or NvChad. The LSP servers are typically managed by a system called mason.nvim. I'm also happy to do a screen recording if it would be helpful, just let me know what you want to see. |
I'll give it a shot tomorrow. It would be super useful to have a repo already set up. You can use our helper to automate that a little with your preferred package manager:
|
I tried what you said in neovim in a react project, using lazyvim and only adding this to the init.lua:
I was not able to reproduce the issue. A screen recording would be good to see exactly what you are doing. |
@dyc3 i just switched my config to At this point I'm guessing that my plugins were being initialized in a different order. I'm going stick with Thank you for the effort that you put into debugging this for me. |
I'm having this issue as well with mason/biome, except my config is lazyvim. |
Environment information
What happened?
I'm using neovim. The first TypeScript file that I open is treated correctly as a TypeScript file, but every other TypeScript file after that is analyzed as if it were a JavaScript file, and it throws syntax warnings about the types.
Here are the server logs for one of the incorrect lints:
You can see in the filename that it's a
.tsx
file, but for whatever reason it's assuminglanguage: JavaScript
instead oflanguage: TypeScript
.Here is the relevant part of my neovim config:
I don't have this same problem with the
eslint
LSP (or any other LSP).Expected result
It should always lint TypeScript files using TypeScript rules, not JavaScript rules.
Code of Conduct
The text was updated successfully, but these errors were encountered: