Skip to content
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

Svelte Language Server Not Picking Up New Schema Tables #8

Open
btab opened this issue Sep 20, 2024 · 3 comments
Open

Svelte Language Server Not Picking Up New Schema Tables #8

btab opened this issue Sep 20, 2024 · 3 comments

Comments

@btab
Copy link

btab commented Sep 20, 2024

Ported over from a discussion on the Convex Community Discord.

  1. I create a new model file goats.ts containing...
import { query } from "./_generated/server";

export const get = query({
  args: {},
  handler: async (ctx) => {
    return await ctx.db.query("goats").collect();
  },
});

This initially gets a red squiggle under "goats" because I guess it's not one of the table names in my schema file.

  1. Then I add the schema for that table...
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";

export default defineSchema({
  [snip...]
  goats: defineTable({
    name: v.string(),
  }),
  [snip...]
});

And if I go back to goats.ts, the red squiggle has disappeared. So VS Code now understands the set of literal table names correctly.

  1. Then I head over to my test svelte route and start typing api. and it completes with prior table names but doesn't offer goats.

  2. If I then restart the Svelte language server, the autocomplete now works as expected. So it's something about the build / transpilation step in Svelte ...maybe?

Note I am runnning both convex dev and npm dev during this scenario so both convex and Svelte are doing their updating magic.

@btab
Copy link
Author

btab commented Sep 20, 2024

Based on a suggestion from @thomasballinger, I tried playing around with extra saves on the various generated files to see whether one such save would nudge the Svelte server into catching up. The good news is that re-saving / touching api.d.ts seems to do so (the added table springs to life in the autocomplete). There might be something about the way that convex is saving that file that is somehow defeating Svelte's file watching - maybe it's being done as a write-then-rename?

So this means that this problem should exist irrespective of whether schemas are involved right? That generated file just comes from the set of api modules in the convex source directory, if I understand it correctly?

@thomasballinger
Copy link
Collaborator

Ah great find! To be clear, of 1 viewing the file in VSCode, 2) saving the file from VSCode, or 3) touching it from the terminal it's 2 and 3 that both fix the problem, making svelte types catch up?

Yep, api.d.ts contains a list of .ts files in the convex/ directory , but doesn't change when the contents of those files change. Without Svelte involved, adding new tables or columns to convex/schema.ts or new export convex functions to other files in the convex/ folder updates types in the browser and autocomplete on things like api.filename.functionName immediately.

@btab
Copy link
Author

btab commented Sep 22, 2024

Yes indeed - anything that would bump the mtime on that generated api TS definition file does the trick.

I also have a secondary (rather weak) signal that I haven't had a chance to investigate. When rapidly building up api files in the convex dir, I found myself quite naturally copying whole existing files (specifically by selecting the file in VS CODE and then copy-pasting it) ... and then modifying the new file accordingly. So foods.ts would be joined by foods copy.ts, which I'd then rename and start hacking on. During this process convex dev is running the whole time.

I have had to force reload the windows a couple of times under these circumstances to get the right code completion even in scripts that have nothing to do with Svelte.

I'm mentioning all this here in case its another mini-clue that the generated files are being instantiated in a somehow LSP-unfriendly way. This problem is proving difficult to reproduce though so I'm not confident in the signal yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants