AdaCore / ada_language_server

Server implementing the Microsoft Language Protocol for Ada and SPARK
GNU General Public License v3.0
226 stars 54 forks source link

declare expressions break the server #1177

Open johnperry-math opened 6 months ago

johnperry-math commented 6 months ago

Declare expressions were introduced in Ada 2022. For example:

function Can_Move (Here, From : Location_Record) return Boolean is
(declare Current : constant Pipe := Map (From.Row, From.Col); begin (
  case Map (Here.Row, Here.Col) is
    when Vertical =>      -- |
      (From.Col = Here.Col and then From.Row - Here.Row = 1
       and then Current /= Horizontal
       and then Current /= ES_Or_NW
       and then Current /= WS_Or_NE)
      or else
      (From.Col = Here.Col and then From.Row - Here.Row = -1
       and then Current /= Horizontal
       and then Current /= SW_Or_EN
       and then Current /= SE_Or_WN),
--  ...

I used this on day 10 of Advent of Code 2023, and while it compiled and ran fine, the VSCode Ada plugin replied

[Error - 4:50:51 PM] Request textDocument/formatting failed.
  Message: day10.adb:1:1: Error formatting node (CompilationUnit). Keeping the initial input selection unchanged
null template: <DeclExpr day10.adb:148:7-208:56>
  Code: -32603

This would seem to be a bug. I realize Ada 2022 support is a work in progress, but if user feedback helps prioritize things... :-)

In fact, I would be willing to contribute to this fix, and will try taking a look at it. Since I've never looked at this before, any suggestions on where to start would be appreciated.

setton commented 6 months ago

Hi @johnperry-math - thank you for the heads-up!

The fix would be adding support for declare expressions above this line https://github.com/AdaCore/libadalang-tools/blob/8702a8f4240fe4cdaaad5c0fdeeb1a27816280fd/src/pp-actions.adb#L4011 - but I wouldn't try to fix this, since we're in the process of changing completely the formatting engine. We'll make sure to support the declare expressions in the new engine.

All the best,

Nicolas