joaotavora / yasnippet

A template system for Emacs
http://joaotavora.github.io/yasnippet/
2.81k stars 311 forks source link

csharp-mode bindings not working (sometimes) #1172

Closed Caliv0 closed 1 year ago

Caliv0 commented 1 year ago

I've created a few snippets for c-sharp, most of them work fine, but some others execute the lisp code and paste its contents but don't snap to the bindings.

Examples

Controller

Doesn't work:

# -*- mode: snippet -*-
# name: controller ... { ... }
# key: controller
# --

using Microsoft.AspNetCore.Mvc;

namespace ${3:Project}.Controllers;

[ApiController]
[Route("${2:[controller]}")]
public class ${1:Name}Controller : ControllerBase
{
    public $1Controller()
    {}
}

Works:

# -*- mode: snippet -*-
# name: controller ... { ... }
# key: controller
# --

namespace ${3:Project}.Controllers;

[ApiController]
[Route(\"${2:[controller]}\")]
public class ${1:Name}Controller : ControllerBase
{
    public $1Controller()
    {}
}

The using statement at the beginning seems to be the problem. NOTE: It does work despite the namespace statement at the beginning.

Exception

Works:

# -*- mode: snippet -*-
# name: exception ... { ... }
# key: exception
# --

public class ${1:Name}Exception : Exception
{
    public $1Exception()
    {
    }

    public $1Exception(string message)
        : base(message)
    {
    }

    public $1Exception(string message, Exception inner)
        : base(message, inner)
    {
    }
}

Doesn't work:

# -*- mode: snippet -*-
# name: exception ... { ... }
# key: exception
# --

namespace Somewhere.Something;

public class ${1:Name}Exception : Exception
{
    public $1Exception()
    {
    }

    public $1Exception(string message)
        : base(message)
    {
    }

    public $1Exception(string message, Exception inner)
        : base(message, inner)
    {
    }
}

The namespace statement at the beginning seems to be the problem

Possible Causes

I've tried to escape as much as possible. I also tried to experiment with the C# syntax, thinking it might be a lsp issue.

Environment

I'm using doom Emacs 29.1 The language server I use is Omnisharp. I've tested it in both C# projects and with C-c C-t in the snippet directly.

Could someone assist me in troubleshooting this issue, or is it a bug?

Caliv0 commented 1 year ago

I installed emacs on my Arch machine by installing this package extra/emacs-naivecomp.

This package didn't have SVG support, so I uninstalled it in favor of emacs-git. After the reinstallation, everything worked just fine.