Skip to content

LuaCATS/lpeg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Luarocks

Definitions for the LPeg library

Type definitions for the LPeg library.

Patterns vs. Captures

Functions and operators in LPeg can be split into two main groups. One that creates patterns and one that creates captures. The corresponding types are called Pattern and Capture. For example lpeg.P('a') returns a Pattern while lpeg.Cc('a') returns a Capture. Technically however, each capture is also a pattern. In other words Capture is an alias of Pattern.

Tooltips

Whether the tooltips of your editor display a capture type as Capture or Pattern depends on the hover.expandAlias setting in the configuration file of lua-language-server.

Here are two screenshots showing the different behavior. If hover.expandAlias is false, the tooltip for a function like lpeg.Cc() displays the return type as Capture:

hover.expandAlias equals false

If hover.expandAlias is true, the tooltip displays the return type as Pattern:

hover.expandAlias equals true

Configuration

Lua-language-server provides several configuration file for defining settings like hover.expandAlias, and they are all explained in the documentation of lua-language-server.

One way to configure it is the following: Create a JSON file .luarc.json in the top-level directory of your workspace with the following content. If this configuration file already exists, just add the expandAlias key.

{
   "Lua" : {
      "hover" : {
         "expandAlias" : false,
      },
   },
}