Commit Graph
125 Commits
Author SHA1 Message Date
José Valim 0e59c68428 Do not crash on duplicate bindings, closes #11378 2021-11-10 19:27:59 +01:00
Michał Łępicki dec273346a Ensure Code.string_to_quoted input only needs the List.Chars protocol (#11344) 2021-10-25 22:07:55 +02:00
José Valim f2ad9823d8 Only consider StartColumn on first line 2021-10-25 16:33:16 +02:00
felipe stival edcb9096d5 Show code snippet on syntax and token missing errors (#11332)
Closes #11280.
2021-10-25 16:18:29 +02:00
José Valim ec459bcfb4 Move cursor_context to Code.Fragment 2021-07-23 12:37:49 +02:00
José Valim 8d5c07c1a4 Do not return context tuples on optimized eval 2021-07-22 08:10:07 +02:00
José Valim cc99995f76 Add operator handling to Code.cursor_context 2021-07-21 18:59:43 +02:00
v0idpwn 432d321189 Fix autocomplete on atoms with at 2021-07-21 15:42:52 +02:00
José Valim f248a52183 Code.cursor_context/2 (#10915) 2021-04-20 11:45:00 +02:00
José Valim 7d3a336980 Move parser tests to its own file and clean up private API 2021-03-20 11:20:37 +01:00
José Valim bc63b5fb80 Add ensure_compiled! to better handle deadlocks, closes #10802 2021-03-16 23:01:29 +01:00
José Valim 75413fe127 Take \r\n into account when computing heredoc indentation 2020-12-06 15:20:50 +01:00
José Valim 0999441e77 Preserve CRLF for heredocs, closes #10504 2020-11-29 11:26:24 +01:00
José Valim e4137546a7 Do not raise when checking for ambiguity with static_atoms_encoder, closes #10501 2020-11-20 12:43:25 +01:00
José Valim 15d791547c Ignore tracers if lexical tracker is dead or explicitly nil 2020-10-11 00:15:25 +02:00
José Valim e1e8f9afec Add column information to SyntaxError and TokenMissingError 2020-08-12 20:14:31 +02:00
José Valim 8bcbfe9a87 Do not send keyword through static_atoms_encoder, closes #9996 2020-04-29 11:09:05 +02:00
José Valim 7052f2b31d Remove race condition with cli test 2020-03-01 11:59:03 +01:00
Wojtek Mach 561338d5e6 Return [{mod, bin}] from Code.compile_file/2, require_file/2, load_file/2 (#9864)
This was the documented behaviour on 1.9 that was broken on v1.10: (version `git` is this branch)

    $ cat a.ex
    defmodule A, do: nil

    $ for v in 1.9.4-otp-22 1.10.2-otp-22 git; do asdf local elixir $v && echo $v; elixir -e 'IO.inspect Code.compile_file("a.ex")'; done
    1.9.4-otp-22
    [{A, <<70, 79, ...>>}
    1.10.2-otp-22
    [{A, %{attributes: [], ...}]
    git
    [{A, <<70, 79, ...>>}

    $ for v in 1.9.4-otp-22 1.10.2-otp-22 git; do asdf local elixir $v && echo $v; elixir -e 'IO.inspect Code.require_file("a.ex")'; done
    1.9.4-otp-22
    [{A, <<70, 79, ...>>}]
    1.10.2-otp-22
    [{A, %{attributes: [], ...}]
    git
    [{A, <<70, 79, ...>>}]

    $ for v in 1.9.4-otp-22 1.10.2-otp-22 git; do asdf local elixir $v && echo $v; elixir -e 'IO.inspect Code.load_file("a.ex")'; done
    1.9.4-otp-22
    [{A, <<70, 79, ...>>}]
    1.10.2-otp-22
    warning: Code.load_file/1 is deprecated. Use Code.require_file/2 or Code.compile_file/2 instead
      nofile:1

    [{A, %{attributes: [], ...}]
    git
    warning: Code.load_file/1 is deprecated. Use Code.require_file/2 or Code.compile_file/2 instead
      nofile:1

    [{A, <<70, 79, ...>>}]
2020-03-01 00:50:14 +01:00
José Valim 9d56a019ee Add application tracers to Mix
This tracer is used to validate that all modules being invoked
in an application belongs to an application that is currently
listed as a dependency. This will help enforce umbrella application
boundaries and help users discover when they depend on Elixir and
Erlang libraries without declaring them upfront.

Thanks to @sasajuric for the proof of the concept and insights
that made this feature possible.

Closes #9847.
2020-02-28 16:05:34 +01:00
José Valim 534d8eac6b Do not emit invalid code when formatting assocs in maps, closes #9771 2020-02-01 11:18:28 +01:00
Wojtek Mach 7287ae758a Fix bug: move :indentation from sigil meta to binary meta (#9738)
We need it there so we can retrieve it like this:

    defmacro sigil_E({:<<>>, meta, [expr]}, []) do
      options = [
        line: __CALLER__.line + 1,
        indentation: meta[:indentation] || 0
      ]

      EEx.compile_string(expr, options)
    end
2020-01-15 16:11:38 +01:00
Wojtek Mach 331df3587b Add :indentation to sigil heredoc meta (#9725) 2020-01-14 20:45:24 +01:00
Eric Meadows-Jönsson c4db8841ab Improve type check error message (#9705)
A type error may not always cause a clause to fail.

Related to #9700.
2020-01-09 15:17:19 +01:00
Devon Estes ec65f8d48a Always capture delimiter metadata for sigils (#9671)
This makes it so we're always capturing delimiter metadata for sigils
instead of requiring the `token_metadata` option. This means that we can
now show the correct sigils in ExUnit diffs (and elsewhere) for code
examples.
2020-01-05 16:07:58 +01:00
José Valim ba619b1c3e Add Application.compile_env/3 (#9628)
Mix stores the compile_env in each applications' .app file.

Releases and Mix tasks were also changed to validate against
the runtime configuration against any stored `compile_env`.
In case of mismatches, an error is raised during boot.
2019-12-06 17:23:01 +01:00
José Valim ac4548f7cc Deprecate Code.ensure_compiled?/1
There are many implications behind using Code.ensure_compiled?/1,
so we do not want to hide it behind a simple boolean check.
Instead use `Code.ensure_compiled/1` which is clearer about intent
and on return values.
2019-11-17 18:47:31 +01:00
José Valim e1f347b75a Add async: true to tests using capture_io :stderr 2019-11-15 10:00:16 +01:00
Fernando Tapia Rico 1bfebe66a3 Prevent calling non-async functions in async tests (#9455)
Capturing a named device other than `:stdio`, such as `:stderr`,
happens globally and requires `async: false`.
2019-11-14 08:11:02 +01:00
Eric Meadows-Jönsson c6da1cfaa8 Run checker on Code.require_file/1 (#9393)
Closes #9362.
2019-10-10 23:11:10 +02:00
hoomin 1f1a59d9f2 Standardize function expressions with multiple arities (#9309) 2019-08-22 18:05:15 -07:00
José Valim b08593b9d1 Add compiler tracing (#9247)
This feature allows IDEs and other tools wanting to
perform source code analysis to do so reliably without
a need to reimplement Elixir's compiler expansion and
without relying on Elixir's private APIs.

This commit also adds :parser_options to compiler
options, which allows developers to combine both options
to retrieve more accurate information, such as columns.
2019-08-02 13:35:12 +02:00
José Valim af9b7889f4 Run the formatter 2019-07-29 15:24:54 +02:00
José Valim ce5602bee1 Include file+line range in eval errors 2019-07-29 15:20:13 +02:00
José Valim f38895cebb Add literal encoder option to Code.string_to_quoted 2019-06-19 00:04:08 +02:00
José Valim 776225f4e1 Add end of expression token information
This also renames pairing_metadata to token_metadata,
as it mostly contains information about related tokens
and not necessarily pairs.
2019-06-18 00:25:22 +02:00
José Valim faefb0b882 Exposing pairing metadata (#9146)
This introduces five new metadata nodes:

  * `do` - contains metadata about do location in a function call with
    `do/end` blocks
  * `end` - contains metadata about end location in a function call with
    `do/end` blocks
  * `closing` - contains metadata about the closing pair, such as a `}`
    in a tuple or in a map, or such as the closing `)` in a function call
    with parens
  * `eol` - is set to true when the opening pair, such as `{` or `(`, are
    followed by the end of the line
  * `delimiter` - contains the opening for sigils (such as `"{"`, `"/"`,
    etc)
2019-06-17 16:38:52 +02:00
José Valim e2c78e8ba9 Rename :end metadata to less ambiguous :closing 2019-06-16 00:01:48 +02:00
José Valim 0229358f88 Ensure third element in location tuple is either nil or an integer 2019-05-09 10:59:13 +02:00
Arjan Scherpenisse cef19c9365 Implement static_atom_encoder tokenizer option (#8956) 2019-04-14 19:44:17 +02:00
José Valim 391e4f6c56 Improve invalid interpolation error message 2019-04-11 12:53:09 +02:00
José Valim a3c5820d12 Properly track files instead of modules in mix integration with lexical tracker 2019-03-15 00:06:41 +01:00
José Valim 6cf3d8c20a Return error tuple for long quoted atoms 2018-07-09 10:49:38 +02:00
José Valim 9cd93a80d5 Add more test cases to invalid interpolation 2018-07-09 10:28:05 +02:00
Adrian Cruz dd880e209c Return an error tuple for interpolation in function call (#7836) 2018-07-09 10:24:26 +02:00
José Valim 2ece95c1db Handle other unescaped tokens in tokenizer 2018-07-03 12:14:16 +02:00
Adrian Cruz 9707843134 Return error on bad hex escaping (#7809)
As discussed in #7270, it would help if we return error tuples
instead of exceptions. This PR does it for string unescaping.
2018-07-03 12:03:43 +02:00
José Valim d27062c8ec Add Code.purge_compiler_modules/0
Closes #7047
2018-06-20 20:51:05 +02:00
José Valim 75541cf472 Condititionally compile and lazily compute __STACKTRACE__ (#7648)
Erlang/OTP 20 warns if the stacktrace is read outside of a
catch/rescue. This commit mirrors this behaviour by consistently
warning on `System.stacktrace/0` being used outside of a
catch/rescue.

Erlang/OTP 21 warns whenever System.stacktrace/:erlang.get_stacktrace
are used. Therefore we need to promote the usage of `__STACKTRACE__`
and make sure to conditionally compile it according to the OTP version.
This requires changes to the Exception normalization mechanism
so we compute `__STACKTRACE__` only when strictly required.

In future Elixir releases, `System.stacktrace/0` will warn when
used even inside catch/rescue.
2018-05-07 15:33:36 +02:00
José Valim b9591267dc Replace Code.load_file/2 by Code.compile_file/2 (#7201)
Currently there is no way to compile a file without leaving
footprints on the system. Plus, the term load_file/2 is very
confusing as loaded is the notation used by modules.

This commit focuses the whole loaded aspect of files exclusively
on require_file/2 (and renames two functions accordingly) and
introduces compile_file/2 which is semantically simpler than
load_file/2.
2018-01-13 22:04:22 +01:00