fortran-language-server icon indicating copy to clipboard operation
fortran-language-server copied to clipboard

Nested "select type" statements not parsed correctly

Open PaulXiCao opened this issue 3 years ago • 2 comments

For nested "select type" statements the syntax highlighting in vscode seems off. The code after the first "end select" is not highlighted anymore until the 2nd "end select".

This is an example code

program main
  implicit none

  type parent
    integer :: i
  end type

  type, extends(parent) :: child
    real :: r
  end type

  class(parent), allocatable :: a, b

  allocate (parent :: a, b)

  select type (x => a)
    type is (parent)
      select type (y => b)
        class is (parent)
        type is (child)
        class default
      end select
    type is (child)     ! not highlighted
    class default       ! not highlighted
  end select            ! not highlighted
end program

This is the debug output of the language server

$ fortls --debug_parser --debug_filepath=main.f90

Testing parser
  File = "main.f90"
  Detected format: free

=========
Parser Output
=========

=== No PreProc ===

program main !!! PROGRAM statement(1)
implicit none !!! IMPLICIT statement(2)
type parent !!! TYPE statement(4)
integer :: i !!! VARIABLE statement(5)
end type !!! END "TYPE" scope(6)
type, extends(parent) :: child !!! TYPE statement(8)
real :: r !!! VARIABLE statement(9)
end type !!! END "TYPE" scope(10)
class(parent), allocatable :: a, b !!! VARIABLE statement(12)
select type (x => a) !!! SELECT statement(16)
type is (parent) !!! SELECT statement(17)
select type (y => b) !!! SELECT statement(18)
class is (parent) !!! SELECT statement(19)
type is (child) !!! SELECT statement(20)
class default !!! SELECT statement(21)
end select !!! END "SELECT" scope(22)
type is (child)     ! not highlighted !!! SELECT statement(23)
class default       ! not highlighted !!! SELECT statement(24)
end select            ! not highlighted !!! END "SELECT" scope(25)
end program !!! END "PROGRAM" scope(27)

=========
Object Tree
=========

1: main
  4: main::parent
    6: main::parent::i
  4: main::child
    6: main::child::r
  6: main::a
  6: main::b
  10: main::#select1
    10: main::#select1::#select2
      6: main::#select1::#select2::x
    10: main::#select1::#select2::#select3
      6: main::#select1::#select2::#select3::x
      10: main::#select1::#select2::#select3::#select4
        6: main::#select1::#select2::#select3::#select4::y
      10: main::#select1::#select2::#select3::#select4::#select5
        6: main::#select1::#select2::#select3::#select4::#select5::y
      10: main::#select1::#select2::#select3::#select4::#select5::#select6
        6: main::#select1::#select2::#select3::#select4::#select5::#select6::y
    10: main::#select1::#select7
      6: main::#select1::#select7::x
    10: main::#select1::#select7::#select8
      6: main::#select1::#select7::#select8::x
4: main::parent
  6: main::parent::i
4: main::child
  6: main::child::r
10: main::#select1
  10: main::#select1::#select2
    6: main::#select1::#select2::x
  10: main::#select1::#select2::#select3
    6: main::#select1::#select2::#select3::x
    10: main::#select1::#select2::#select3::#select4
      6: main::#select1::#select2::#select3::#select4::y
    10: main::#select1::#select2::#select3::#select4::#select5
      6: main::#select1::#select2::#select3::#select4::#select5::y
    10: main::#select1::#select2::#select3::#select4::#select5::#select6
      6: main::#select1::#select2::#select3::#select4::#select5::#select6::y
  10: main::#select1::#select7
    6: main::#select1::#select7::x
  10: main::#select1::#select7::#select8
    6: main::#select1::#select7::#select8::x
10: main::#select1::#select2
  6: main::#select1::#select2::x
10: main::#select1::#select2::#select3
  6: main::#select1::#select2::#select3::x
  10: main::#select1::#select2::#select3::#select4
    6: main::#select1::#select2::#select3::#select4::y
  10: main::#select1::#select2::#select3::#select4::#select5
    6: main::#select1::#select2::#select3::#select4::#select5::y
  10: main::#select1::#select2::#select3::#select4::#select5::#select6
    6: main::#select1::#select2::#select3::#select4::#select5::#select6::y
10: main::#select1::#select2::#select3::#select4
  6: main::#select1::#select2::#select3::#select4::y
10: main::#select1::#select2::#select3::#select4::#select5
  6: main::#select1::#select2::#select3::#select4::#select5::y
10: main::#select1::#select2::#select3::#select4::#select5::#select6
  6: main::#select1::#select2::#select3::#select4::#select5::#select6::y
10: main::#select1::#select7
  6: main::#select1::#select7::x
10: main::#select1::#select7::#select8
  6: main::#select1::#select7::#select8::x

=========
Exportable Objects
=========

1: main

PaulXiCao avatar Oct 25 '20 11:10 PaulXiCao

@PaulXiCao I think what you are experiencing is because the Modern Fortran package has a few bugs when it comes to syntax highlighting. There is a PR open and ready to merge addressing this issue, see https://github.com/krvajal/vscode-fortran-support/pull/201

gnikit avatar Dec 05 '20 20:12 gnikit

I suspect that this is fixed now since it was a Modern Fortran bug

gnikit avatar Oct 05 '21 21:10 gnikit