Skip to content

Elixir support #1844

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

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions data/playground/elixir/calls.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Calls do
a()
b.()
c do
1
end
d() do
end
e() do
1
end
a x do
x
end
f(0) do
1
end
Alias.g()
end
36 changes: 36 additions & 0 deletions data/playground/elixir/data-structures.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule DataStructures do
[]
[a]
[A]
[1]
[1, 2]
[[1], 1]
%{}
%{a: 1, b: 2}
%{:a => 1, "b" => 2, c => 3}
%{"a" => 1, b: 2, c: 3}
%{user | name: "Jane", email: "[email protected]"}
%{user | "name" => "Jane"}
%AStruct{a: 1, b: 2}
%AnotherStruct{:a => 1, "b" => 2, c => 3}
%ThirdStruct{"a" => 1, b: 2, c: 3}
%User{user | name: "Jane", email: "[email protected]"}
%User{user | "name" => "Jane"}
%{
:a => 1,
"b" => 2,
c => 3
}
%_{}
%name{}
%^name{}
%__MODULE__{}
%__MODULE__.Child{}
%:"Elixir.Mod"{}
%fun(){}
%Mod.fun(){}
%fun.(){}
{}
{1}
{1, 2}
end
62 changes: 62 additions & 0 deletions data/playground/elixir/functions.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
defmodule Funcs do
def no_args() do
end

def no_args_no_parens do
end

def one_arg(x) do
x
end

def one_arg_no_parens(x) do
x
end

def two_args(x, y) do
x + y
end

def two_args_no_parens(x, y) do
x + y
end

def default_args_no_parens(x, y \\ 1) do
x + y
end

def default_args(x, y \\ 1) do
x + y
end

def do_block(), do: 1
def do_block(x), do: x

def pattern_matching([{x, y} | tail]) do
x + y
end

def one_guard(x) when x == 1 do
x
end

def multiple_guard(x) when x > 10 when x < 5 do
x
end

defp private(x) do
x
end

defmacro macro(x) do
quote do
[unquote(x)]
end
end

defguard guard(term) when is_integer(term) and rem(term, 2) == 0

def unquote(name)(unquote_splicing(args)) do
unquote(compiled)
end
end
5 changes: 3 additions & 2 deletions packages/common/src/extensionDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ export const extensionDependencies = [
"pokey.parse-tree",

// Register necessary language-IDs for tests
"scala-lang.scala", // scala
"mrob95.vscode-talonscript", // talon
"jakebecker.elixir-ls", // elixir
"jrieken.vscode-tree-sitter-query", // scm
"mrob95.vscode-talonscript", // talon
"scala-lang.scala", // scala

// Necessary for the `drink cell` and `pour cell` tests
"ms-toolsai.jupyter",
Expand Down
13 changes: 13 additions & 0 deletions packages/common/src/scopeSupportFacets/elixir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/naming-convention */

import {
LanguageScopeSupportFacetMap,
ScopeSupportFacetLevel,
} from "./scopeSupportFacets.types";

const { supported } = ScopeSupportFacetLevel;

export const elixirScopeSupport: LanguageScopeSupportFacetMap = {
"collectionItem.map": supported,
"collectionItem.map.iteration": supported,
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { elixirScopeSupport } from "./elixir";
import { htmlScopeSupport } from "./html";
import { javaScopeSupport } from "./java";
import { javascriptScopeSupport } from "./javascript";
Expand Down Expand Up @@ -25,6 +26,8 @@ export function getLanguageScopeSupport(
return talonScopeSupport;
case "typescript":
return typescriptScopeSupport;
case "elixir":
return elixirScopeSupport;
}
throw Error(`Unsupported language: '${languageId}'`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ export const scopeSupportFacetInfos: Record<
scopeType: "argumentOrParameter",
isIteration: true,
},
"collectionItem.map": {
description: "An entry in a map/dictionary",
scopeType: "collectionItem",
},
"collectionItem.map.iteration": {
description:
"Iteration scope for entries in a map/dictionary; should be between the braces",
scopeType: "collectionItem",
isIteration: true,
},

"comment.line": {
description: "A line comment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const scopeSupportFacets = [
"argument.formal",
"argument.formal.iteration",

"collectionItem.map",
"collectionItem.map.iteration",

"comment.line",
"comment.block",

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: elixir
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |
def fun() do
# body
end
selections:
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
marks: {}
finalState:
documentContents: |+

selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
languageId: elixir
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
def fun(x) when x == 1 do
x
end
selections:
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
languageId: elixir
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
defp fun(x) do
x
end
selections:
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: elixir
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
defmacro fun(x) do
quote do
[unquote(x)]
end
end
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
languageId: elixir
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |
defguard is_even(term) when is_integer(term) and rem(term, 2) == 0
selections:
- anchor: {line: 0, character: 26}
active: {line: 0, character: 26}
marks: {}
finalState:
documentContents: |+

selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
languageId: elixir
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
a x do
x
end
selections:
- anchor: {line: 1, character: 3}
active: {line: 1, character: 3}
marks: {}
thrownError: {name: NoContainingScopeError}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: elixir
command:
version: 6
spokenForm: change funk
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: namedFunction}
usePrePhraseSnapshot: true
initialState:
documentContents: |
def fun do
# body
end
selections:
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
marks: {}
finalState:
documentContents: |+

selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Loading