williamthome

williamthome

VS Code regex issue | Elixir snippets

Hi!

In this issue for my pull request in vscode-elixir-snippets, I could not find a solution to the problem.

My regex looks like this

${RELATIVE_FILEPATH/^([^\\/\\\\]+[\\/\\\\])|(\\.ex|\\.exs)$|([^._\\/\\\\]+)|_|([\\/\\\\])/${3:/capitalize}${4:+.}/g}

Works for defmod and ex_unit snippets, but not for supervisor, dynamic_supervisor and gen_server, and the regex is exactly the same!

As described in my question in stackoverflow., the output for lib/shop_web/live/product_live/index.ex should be ShopWeb.Live.ProductLive.Index

Here works perfectly:

 "dmod": {
    "prefix": ["dmod", "defmod"],
    "comments": [
      "Generates the namespace for a file.",
      "e.g. A file with the path `lib/foo/bar/baz/boing.ex` would resolve to Foo.Bar.Baz.Boing.",
    ],
    "body": [
      "defmodule ${RELATIVE_FILEPATH/^([^\\/\\\\]+[\\/\\\\])|(\\.ex|\\.exs)$|([^._\\/\\\\]+)|_|([\\/\\\\])/${3:/capitalize}${4:+.}/g} do",
      "\t$0",
      "end"
    ],
    "description": "def module",
    "scope": "source.elixir"
  },

But here not

 "Supervisor": {
    "prefix": "supervisor",
    "body": [
      "defmodule ${RELATIVE_FILEPATH/^([^\\/\\\\]+[\\/\\\\])|(\\.ex|\\.exs)$|([^._\\/\\\\]+)|_|([\\/\\\\])/${3:/capitalize}${4:+.}/g} do",
      "\tuse Supervisor",
      "",
      "\tdef start_link(${args}) do",
      "\t\tSupervisor.start_link(__MODULE__, [${args}], name: __MODULE__)",
      "\tend",
      "",
      "\tdef init([${args}]) do",
      "\t\tchildren = []",
      "",
      "\t\tSupervisor.init(children, strategy: :one_for_one)",
      "\tend",
      "end"
    ],
    "description": "Insert code for an OTP Supervisor",
    "scope": "source.elixir"
  },

The output for the supervisor snippet is

defmodule ${RELATIVE_FILEPATH/^([^/\]+[/\])|(\.ex|\.exs)$|([^._/\]+)|_|([/\])//capitalize,+./g} do
  use Supervisor

  def start_link(args) do
    Supervisor.start_link(__MODULE__, [args], name: __MODULE__)
  end

  def init([args]) do
    children = []

    Supervisor.init(children, strategy: :one_for_one)
  end
end

And the same issue is for dynamic_supervisor and gen_server snippets.

Can someone give me a help?

Marked As Solved

williamthome

williamthome

Found what I was missing.

e.g. Instead of ${args} the correct syntax is ${1:args}.

This solves the problem.

Also Liked

williamthome

williamthome

Ok. Thanks for the reply! :grin:

Jarmon7815

Jarmon7815

It is easy to add code snippets to visual studio code both for your own use or to share with others on the public marketplace.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement