winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.05k stars 196 forks source link

rfc: retrieve type information of a wing program from the console #3638

Open skyrpex opened 1 year ago

skyrpex commented 1 year ago

The Console could use as much Type Information from a Wing Program as possible. We should find a way to retrieve such data and associate it with a given construct.

Type data that we're looking for:

Proposal

The Wing Compiler will generate, along with tree.json and simulator.json, a types.json with the following data:

{
  types: [
    {
      // The id can be the class name and a hash of the filename, line and column.
      // It doesn't need to be universally unique between different compilations.
      // I guess the Wing LSP already generates something like this.
      id: "MyBucket-12d3f53f",
      className: "MyBucket",
      filename: "index.w",
      line: 1,
      column: 12,

      inflights: [
        {
          // `inflight putFile(key: str, body: str): void`
          name: "putFile",
          type: "input",
          arguments: [
            {
              name: "key",
              type: "str",
            },
            {
              name: "body",
              type: "str",
            },
          ],
          return: {
            type: "void",
          },
        },
        {
          name: "onFileCreated",
          type: "output",
          eventType: {
            type: "struct",
            fields: [
              {
                name: "key",
                type: "str",
              },
              {
                name: "type",
                type: "BucketEventType-23f23ffe",
                // To describe: fields from custom types...
              },
            ],
          },
        },
      ],
    },
  ],
}
Chriscbr commented 1 year ago

Is it possible for the Wing Console to retrieve type information by talking with the language server maybe?

skyrpex commented 1 year ago

I think so, but I guess we'll need more than a resource path (eg, root/Default/cloud.Counter) to retrieve information about that specific resource, right? Like a symbol from the wingfile?

@MarkMcCulloh any insights? 🙏🏻

MarkMcCulloh commented 1 year ago

The primary way of inspecting data in the language server is with a file position. In the console, we'd need this for each constuct. This is not easy, and tbh if we get that working I doubt we'd need to use the language server at all since we could just store all the data per your example.

The language server is meant to inspect wing source code, not the synthed output (or even intermediate JS). So in general it probably wouldn't be a good idea for this use case. We may be able to extract some of the introspection logic though.

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 11 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 8 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 5 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!