Advertisement
Guest User

neovim Garmin MonkeyC lspconfig

a guest
Mar 19th, 2025
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.42 KB | Source Code | 0 0
  1.       -- Define a custom language server for monkeyc
  2.       local configs = require("lspconfig.configs")
  3.       local lspconfig = require("lspconfig")
  4.  
  5.       local function get_language_server_path()
  6.         local workspace_dir = table.concat(vim.fn.readfile(vim.fn.expand("~/.Garmin/ConnectIQ/current-sdk.cfg")), "\n")
  7.         local jar_path = workspace_dir .. "/bin/LanguageServer.jar"
  8.  
  9.         if vim.fn.filereadable(jar_path) == 1 then
  10.           return jar_path
  11.         end
  12.         print("Monkey C Language Server not found: " .. jar_path)
  13.         return nil
  14.       end
  15.  
  16.       local monkeyc_lsp_jar = get_language_server_path()
  17.       if monkeyc_lsp_jar then
  18.         -- To enable tracing of the official VSCode plugin, add the following snippet
  19.         -- under "contributes" -> "configuration" -> "properties"
  20.         -- in ~/.vscode/extensions/garmin.monkey-c-1.1.1/package.json
  21.         --
  22.         -- "monkeyc.trace.server": {
  23.         --  "scope": "window",
  24.         --  "type": "string",
  25.         --  "enum": [
  26.         --      "off",
  27.         --      "messages",
  28.         --      "verbose"
  29.         --  ],
  30.         --  "default": "verbose",
  31.         --  "description": "Traces the communication between VS Code and the language server."
  32.         -- },
  33.         --
  34.         -- Then open a MonkeyC project and check the VSCode "Output" window
  35.         --
  36.         -- To debug the nvim plugin:
  37.         -- tail -f ~/.local/state/nvim/lsp.log
  38.         --
  39.         -- Uncomment the following to enable debug logging
  40.         -- vim.lsp.set_log_level("debug")
  41.         --
  42.         -- Open a MonkeyC project and check the lsp.log output
  43.         --
  44.  
  45.         local monkeycLspCapabilities = vim.lsp.protocol.make_client_capabilities()
  46.         -- Need to set some variables in the client capabilities to prevent the
  47.         -- LanguageServer from raising exceptions
  48.         monkeycLspCapabilities.textDocument.declaration.dynamicRegistration = true
  49.         monkeycLspCapabilities.textDocument.implementation.dynamicRegistration = true
  50.         monkeycLspCapabilities.textDocument.typeDefinition.dynamicRegistration = true
  51.         monkeycLspCapabilities.textDocument.documentHighlight.dynamicRegistration = true
  52.         monkeycLspCapabilities.workspace = {
  53.           didChangeWorkspaceFolders = {
  54.             dynamicRegistration = true,
  55.           },
  56.         }
  57.         monkeycLspCapabilities.textDocument.foldingRange = {
  58.           lineFoldingOnly = true,
  59.           dynamicRegistration = true,
  60.         }
  61.  
  62.         if not configs.monkeyc_ls then
  63.           local root = lspconfig.util.root_pattern("manifest.xml") or vim.fn.getcwd()
  64.           configs.monkeyc_ls = {
  65.             default_config = {
  66.               cmd = {
  67.                 "java",
  68.                 "-Dapple.awt.UIElement=true",
  69.                 "-classpath",
  70.                 monkeyc_lsp_jar,
  71.                 "com.garmin.monkeybrains.languageserver.LSLauncher",
  72.               },
  73.               filetypes = { "monkeyc", "jungle", "mss" },
  74.               root_dir = root,
  75.               settings = {
  76.                 {
  77.                   developerKeyPath = vim.g.monkeyc_connect_iq_dev_key_path
  78.                     or vim.fn.expand("~/.Garmin/connect_iq_dev_key.der"),
  79.                   compilerWarnings = true,
  80.                   compilerOptions = vim.g.monkeyc_compiler_options or "",
  81.                   developerId = "",
  82.                   jungleFiles = "monkey.jungle",
  83.                   javaPath = "",
  84.                   typeCheckLevel = "Default",
  85.                   optimizationLevel = "Default",
  86.                   testDevices = {
  87.                     "enduro3", -- get this dynamically from the manifest file
  88.                   },
  89.                   debugLogLevel = "Default",
  90.                 },
  91.               },
  92.               capabilities = monkeycLspCapabilities,
  93.               init_options = {
  94.                 publishWarnings = vim.g.monkeyc_publish_warnings or true,
  95.                 compilerOptions = vim.g.monkeyc_compiler_options or "",
  96.                 typeCheckMsgDisplayed = true,
  97.                 workspaceSettings = {
  98.                   {
  99.                     path = root(vim.fn.getcwd()),
  100.                     jungleFiles = {
  101.                       root(vim.fn.getcwd()) .. "/monkey.jungle",
  102.                     },
  103.                   },
  104.                 },
  105.               },
  106.             },
  107.           }
  108.         end
  109.  
  110.         -- print(vim.lsp.client.config)
  111.         lspconfig.monkeyc_ls.setup({})
  112.       end
  113.  
Tags: monkey-c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement