mhanberg

mhanberg

Expert LSP Core Team

The docs state:

  • :end_of_expression - denotes when the end of expression effectively happens. Available for all expressions except the last one inside a __block__ (when :token_metadata is true)

My question is about “except the last one inside a __block__”.

Is limitation based on the existing parser implementation or is there an “actual” (in quotes because I’m not sure the right wording here haha) reason for the exception?

cc @josevalim

Showing Posts 1 to 10

mhanberg

mhanberg OP

Expert LSP Core Team

Another question actually, is end_of_expression only included if the end of the expression cannot be computed from {line, column + length(token)}?

josevalim

josevalim

Creator of Elixir

I think it is because the last expression end is marked inside the __block__ already. But we can add more metadata if necessary.

lukaszsamson

lukaszsamson

ElixirLS Core Team
mhanberg

mhanberg OP

Expert LSP Core Team

I’ll look into it more to confirm, thanks!

mhanberg

mhanberg OP

Expert LSP Core Team

Given the following code and result from Code.string_to_quoted/2

iex(4)> Code.string_to_quoted(~S'''
...(4)>       defmodule Foo do
...(4)>         use AnotherMod.Nested,
...(4)>           some: :option
...(4)>
...(4)>         def run(arg) do
...(4)>           bar()
...(4)>           :ok
...(4)>         end
...(4)>       end
...(4)> ''', columns: true, token_metadata: true)
{:ok,
 {:defmodule,
  [do: [line: 1, column: 21], end: [line: 9, column: 7], line: 1, column: 7],
  [
    {:__aliases__, [last: [line: 1, column: 17], line: 1, column: 17], [:Foo]},
    [
      do: {:__block__, [],
       [
         {:use,
          [
            end_of_expression: [newlines: 2, line: 3, column: 24],
            line: 2,
            column: 9
          ],
          [
            {:__aliases__, [last: [line: 2, column: 24], line: 2, column: 13],
             [:AnotherMod, :Nested]},
            [some: :option]
          ]},
         {:def,
          [
            do: [line: 5, column: 22],
            end: [line: 8, column: 9],
            line: 5,
            column: 9
          ],
          [
            {:run, [closing: [line: 5, column: 20], line: 5, column: 13],
             [{:arg, [line: 5, column: 17], nil}]},
            [
              do: {:__block__, [],
               [
                 {:bar,
                  [
                    end_of_expression: [newlines: 1, line: 6, column: 17],
                    closing: [line: 6, column: 15],
                    line: 6,
                    column: 11
                  ], []},
                 :ok
               ]}
            ]
          ]}
       ]}
    ]
  ]}}

I am wondering what is the criteria that makes the use call and the bar() function call get an :end_of_expression metadata, but not any of the other expressions?

I am not hoping for any particular answer, just want to know exactly how it works so I can reproduce it in Spitfire.

Thanks @josevalim.

mhanberg

mhanberg OP

Expert LSP Core Team

Actually maybe I have figured it out moments after posting.

Is it because the the tokens given to use are just AST, and not actually “expressions” at parse time, since use is a macro? Same thing for the arguments to def, and def and :ok being the last expression inside their do blocks?

josevalim

josevalim

Creator of Elixir

They are all expressions. The current docs state though that end_of_expression is added only to expressions with a __block__ (except the last one). The purpose of end_of_expression was to format blocks properly, which is why it is limited in scope. We could add it to all constructs in a block though. Adding them to everything is a taller order (and probably not that useful).

mhanberg

mhanberg OP

Expert LSP Core Team

Oh, this was a missing piece then for me.

The current docs don’t actually mention that it’s only expressions in a block

denotes when the end of expression effectively happens. Available for all expressions except the last one inside a __block__ (when :token_metadata is true)

I can easily incorporate this I think.

Thanks for helping me understand this! :person_bowing:t2:

PS: I don’t personally have a need to increase or decrease the metadata currently, just needed to know how the existing metadata works.

josevalim

josevalim

Creator of Elixir

Yeah. I actually tried to say that but my english failed me. :smiley:

mhanberg

mhanberg OP

Expert LSP Core Team

This is obvious now that I knew where to look in elixir_parser.yrl.

Thanks again for the help José!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews