activate treesitter diagnostics when file is freshly opened

Hi,

this file has a syntax error on line 3 (missing ‘f’) but treesitter doesn’t recognize ist when I just have opened this file:

I expect this when I open a file:

At this moment treesitter start diagnostics for example when I delete or misspell a keyword.
How can I achieve this so that treesitter recognize this error when a file is opened?

Maybe it has something to do with:
capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = true

return {
    "neovim/nvim-lspconfig",
    config = function()
      local capabilities = require('cmp_nvim_lsp').default_capabilities()
      capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = true,

I get this error: attempt to index field ‘workspace’ (a nil value)
(I have not really a clue what I’m doing. I don’t know where to put this line of code nor do I know if actually solves my problem)

nvim v0.9.2

lsp_config.lua

return {
    "neovim/nvim-lspconfig",
    config = function()
        -- Set up lspconfig.
      local capabilities = require('cmp_nvim_lsp').default_capabilities()
      -- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
    require('lspconfig').lua_ls.setup {
        capabilities = capabilities,
        on_init = function (client)
            end,
      }
        -- Setup language servers.
        local lspconfig = require('lspconfig')
        lspconfig.pyright.setup {}
        lspconfig.tsserver.setup {}
        lspconfig.rust_analyzer.setup {
          -- Server-specific settings. See `:help lspconfig-setup`
          settings = {
            ['rust-analyzer'] = {},
          },
        }
    end
}