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

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
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

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
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
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement