Skip to content

How do I configure the server to detect globals injected into the environment? #1766

@myk002

Description

@myk002

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Annotations, Type Checking, Completion, Diagnostics/Syntax Checking, Hover

Expected Behaviour

Globals that are defined in a common Lua file that are automatically injected into all project Lua modules are detected by lua-language-server

Actual Behaviour

Injected globals are marked as "Undefined global"

Reproduction steps

  1. git clone https://github.com/DFHack/dfhack.git
    (you don't have to pull the submodules unless you actually want to build)
  2. Open library/lua/class.lua (or really any other file)
  3. See that mkmodule is shown as undefined

Additional Notes

Our system pre-populates the Lua _ENV for each module with globals defined in library/lua/dfhack.lua, including mkmodule, extensions to the string builtin, and other things. We also inject symbols defined in C, but just recognizing the Lua globals would be wonderful.

Can I mark this file as "included by default" when analyzing other lua files?

Log File

service.log
$ cat service.log 
[09:33:16.844][info] [#0:/home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/main.lua:66]: Lua Lsp startup, root:   /home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server
[09:33:16.844][info] [#0:/home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/main.lua:67]: ROOT:    /home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server
[09:33:16.844][info] [#0:/home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/main.lua:68]: LOGPATH: /home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/log
[09:33:16.844][info] [#0:/home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/main.lua:69]: METAPATH:        /home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/meta
[09:33:16.844][info] [#0:/home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/main.lua:70]: VERSION: 3.6.4-dev
[09:33:16.866][debug][#0:script/service/telemetry.lua:22]: Telemetry Token:     7B9BFED764B17AFF
[09:33:16.873][debug][#0:script/pub/pub.lua:50]: Create brave:  1
[09:33:16.873][debug][#0:script/pub/pub.lua:50]: Create brave:  2
[09:33:16.873][debug][#0:script/pub/pub.lua:50]: Create brave:  3
[09:33:16.873][debug][#0:script/pub/pub.lua:50]: Create brave:  4
[09:33:16.873][info] [#0:script/service/service.lua:141]: 
========= Medical Examination Report =========
    --------------- Memory ---------------
        Total: 1.566 MB
        # 00 : 1.566 MB
        # 01 : 0.000 MB
        # 02 : 0.000 MB
        # 03 : 0.000 MB
        # 04 : 0.000 MB
    --------------- Coroutine ---------------
        Total:     0
        Running:   0
        Suspended: 0
        Normal:    0
        Dead:      0
    --------------- Cache ---------------
        Total: 1
        Dead:  0
    ---------------  RPC  ---------------
        Holdon:   0
        Waiting:  0
==============================================
[09:33:16.878][debug][#0:script/client.lua:463]: Client init    {
  capabilities = {
    general = {
      markdown = {
        allowedTags = { "ul", "li", "p", "code", "blockquote", "ol", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "em", "pre", "table", "thead", "tbody", "tr", "th", "td", "div", "del", "a", "strong", "br", "img", "span" },
        parser = "marked",
        version = "1.1.0"
      },
      positionEncodings = { "utf-16" },
      regularExpressions = {
        engine = "ECMAScript",
        version = "ES2020"
      },
      staleRequestSupport = {
        cancel = true,
        retryOnContentModified = { "textDocument/semanticTokens/full", "textDocument/semanticTokens/range", "textDocument/semanticTokens/full/delta" }
      }
    },
    notebookDocument = {
      synchronization = {
        dynamicRegistration = true,
        executionSummarySupport = true
      }
    },
    textDocument = {
      callHierarchy = {
        dynamicRegistration = true
      },
      codeAction = {
        codeActionLiteralSupport = {
          codeActionKind = {
            valueSet = { "", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" }
          }
        },
        dataSupport = true,
        disabledSupport = true,
        dynamicRegistration = true,
        honorsChangeAnnotations = false,
        isPreferredSupport = true,
        resolveSupport = {
          properties = { "edit" }
        }
      },
      codeLens = {
        dynamicRegistration = true
      },
      colorProvider = {
        dynamicRegistration = true
      },
      completion = {
        completionItem = {
          commitCharactersSupport = true,
          deprecatedSupport = true,
          documentationFormat = { "markdown", "plaintext" },
          insertReplaceSupport = true,
          insertTextModeSupport = {
            valueSet = { 1, 2 }
          },
          labelDetailsSupport = true,
          preselectSupport = true,
          resolveSupport = {
            properties = { "documentation", "detail", "additionalTextEdits" }
          },
          snippetSupport = true,
          tagSupport = {
            valueSet = { 1 }
          }
        },
        completionItemKind = {
          valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }
        },
        completionList = {
          itemDefaults = { "commitCharacters", "editRange", "insertTextFormat", "insertTextMode" }
        },
        contextSupport = true,
        dynamicRegistration = true,
        insertTextMode = 2
      },
      declaration = {
        dynamicRegistration = true,
        linkSupport = true
      },
      definition = {
        dynamicRegistration = true,
        linkSupport = true
      },
      diagnostic = {
        dynamicRegistration = true,
        relatedDocumentSupport = false
      },
      documentHighlight = {
        dynamicRegistration = true
      },
      documentLink = {
        dynamicRegistration = true,
        tooltipSupport = true
      },
      documentSymbol = {
        dynamicRegistration = true,
        hierarchicalDocumentSymbolSupport = true,
        labelSupport = true,
        symbolKind = {
          valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }
        },
        tagSupport = {
          valueSet = { 1 }
        }
      },
      foldingRange = {
        dynamicRegistration = true,
        foldingRange = {
          collapsedText = false
        },
        foldingRangeKind = {
          valueSet = { "comment", "imports", "region" }
        },
        lineFoldingOnly = true,
        rangeLimit = 5000
      },
      formatting = {
        dynamicRegistration = true
      },
      hover = {
        contentFormat = { "markdown", "plaintext" },
        dynamicRegistration = true
      },
      implementation = {
        dynamicRegistration = true,
        linkSupport = true
      },
      inlayHint = {
        dynamicRegistration = true,
        resolveSupport = {
          properties = { "tooltip", "textEdits", "label.tooltip", "label.location", "label.command" }
        }
      },
      inlineValue = {
        dynamicRegistration = true
      },
      linkedEditingRange = {
        dynamicRegistration = true
      },
      onTypeFormatting = {
        dynamicRegistration = true
      },
      publishDiagnostics = {
        codeDescriptionSupport = true,
        dataSupport = true,
        relatedInformation = true,
        tagSupport = {
          valueSet = { 1, 2 }
        },
        versionSupport = false
      },
      rangeFormatting = {
        dynamicRegistration = true
      },
      references = {
        dynamicRegistration = true
      },
      rename = {
        dynamicRegistration = true,
        honorsChangeAnnotations = true,
        prepareSupport = true,
        prepareSupportDefaultBehavior = 1
      },
      selectionRange = {
        dynamicRegistration = true
      },
      semanticTokens = {
        augmentsSyntaxTokens = true,
        dynamicRegistration = true,
        formats = { "relative" },
        multilineTokenSupport = false,
        overlappingTokenSupport = false,
        requests = {
          full = {
            delta = true
          },
          range = true
        },
        serverCancelSupport = true,
        tokenModifiers = { "declaration", "definition", "readonly", "static", "deprecated", "abstract", "async", "modification", "documentation", "defaultLibrary" },
        tokenTypes = { "namespace", "type", "class", "enum", "interface", "struct", "typeParameter", "parameter", "variable", "property", "enumMember", "event", "function", "method", "macro", "keyword", "modifier", "comment", "string", "number", "regexp", "operator", "decorator" }
      },
      signatureHelp = {
        contextSupport = true,
        dynamicRegistration = true,
        signatureInformation = {
          activeParameterSupport = true,
          documentationFormat = { "markdown", "plaintext" },
          parameterInformation = {
            labelOffsetSupport = true
          }
        }
      },
      synchronization = {
        didSave = true,
        dynamicRegistration = true,
        willSave = true,
        willSaveWaitUntil = true
      },
      typeDefinition = {
        dynamicRegistration = true,
        linkSupport = true
      },
      typeHierarchy = {
        dynamicRegistration = true
      }
    },
    window = {
      showDocument = {
        support = true
      },
      showMessage = {
        messageActionItem = {
          additionalPropertiesSupport = true
        }
      },
      workDoneProgress = true
    },
    workspace = {
      applyEdit = true,
      codeLens = {
        refreshSupport = true
      },
      configuration = true,
      diagnostics = {
        refreshSupport = true
      },
      didChangeConfiguration = {
        dynamicRegistration = true
      },
      didChangeWatchedFiles = {
        dynamicRegistration = true,
        relativePatternSupport = true
      },
      executeCommand = {
        dynamicRegistration = true
      },
      fileOperations = {
        didCreate = true,
        didDelete = true,
        didRename = true,
        dynamicRegistration = true,
        willCreate = true,
        willDelete = true,
        willRename = true
      },
      inlayHint = {
        refreshSupport = true
      },
      inlineValue = {
        refreshSupport = true
      },
      semanticTokens = {
        refreshSupport = true
      },
      symbol = {
        dynamicRegistration = true,
        resolveSupport = {
          properties = { "location.range" }
        },
        symbolKind = {
          valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }
        },
        tagSupport = {
          valueSet = { 1 }
        }
      },
      workspaceEdit = {
        changeAnnotationSupport = {
          groupsOnLabel = true
        },
        documentChanges = true,
        failureHandling = "textOnlyTransactional",
        normalizesLineEndings = true,
        resourceOperations = { "create", "rename", "delete" }
      },
      workspaceFolders = true
    }
  },
  clientInfo = {
    name = "Visual Studio Code",
    version = "1.74.0"
  },
  initializationOptions = {
    changeConfiguration = true
  },
  locale = "en-us",
  processId = 11055,
  rootPath = "/home/myk/src/dfhack",
  rootUri = "file:///home/myk/src/dfhack",
  trace = "off",
  workDoneToken = "5d4684ea-c503-496c-917e-ae53116a5010",
  workspaceFolders = { {
      name = "dfhack",
      uri = "file:///home/myk/src/dfhack"
    } }
}
[09:33:16.878][info] [#0:script/language.lua:137]: VSC language: en-us
[09:33:16.878][info] [#0:script/language.lua:138]: LS  language: en-us
[09:33:16.878][info] [#0:script/workspace/workspace.lua:38]: Workspace init root:       file:///home/myk/src/dfhack
[09:33:16.878][info] [#0:script/workspace/workspace.lua:42]: Log path:  /home/myk/.vscode/extensions/sumneko.lua-3.6.4-linux-x64/server/log/file_home_myk_src_dfhack.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionUser has a question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions