Linting and Code Navigation in the code editor

I’m getting “line is too long (240 > 120)”, is this anything to worry about?

Well, long lines are hard to read and could be a sign that you should split something like long if-statements into several shorter ones. But no, it is not an actual error.

You can disable this warning by creating a .luacheckrc file in the root of your project and setting max_line_length to either false (to disable the warning) or a larger number that you are comfortable with.

Read more about the config options and the .luacheckrc file here:

https://luacheck.readthedocs.io/en/stable/config.html

2 Likes

An update for Defold linting capabilities is out now! The newly supported LSP feature is workspace diagnostics that we now perform when building the project:

With workspace diagnostics, you get project-wide linting results in the “Build Errors” view.

To try it out:

  1. Make sure you are using the latest version of the editor
  2. Set language server dependency to a new URL — https://github.com/defold/lua-language-server/releases/download/v0.0.4/release.zip
20 Likes

Works Great. This is awesome!

5 Likes

This is amazing!!! Thanks for implementing it! Is there any specific release in mind for its integration into the editor?

1 Like

The latest version of the Lua LSP should work with any recent version of the Defold editor.

1 Like

Ohh, completely forgot to share here… The editor now supports code navigation powered by Language Servers! Use F12 for Go to Definition and Shift F12 for Find References actions.

11 Likes

This is really handy! Especially Shift F12, since I tend to do a file search to get this info. :star_struck:

5 Likes

I tried it out and it works perfectly. Thanks!

1 Like

I can’t get it to work. F12 gets me nowhere, shift-F12 shows no gui

You can check logs in Help → Show Logs

I didn’t explain myself well. I know where the logs are, I was wondering if there are any particular logs I should look for related to the problem

You could look for messages like “Language server process failed to start”, or “Language server failed”.
Also, note that the Lua language server can’t navigate to built-in Defold Lua functions or to functions from library dependencies.

No log that contains the word “Language”

these two cases should work right?

common.lua

local M = {}

function M.some_function(x)
	return x + 1
end

return M

test.script

local common = require "main/common"

local function get_some_number()
	return 42
end

function init(self)
	local x = common.some_function(1)	
	local num = get_some_number()	
end

Hmm, shouldn’t it be "main.common" instead of "main/common"?

1 Like

I think both syntaxes are supported, or am I wrong? in any case the problem does not change even using the ‘.’

You should use “.” as that is universally the path separator, regardless of OS

Understood. however the problem remains, f12 and shift-f12 do nothing.

1 Like

Please share a small repro project that shows the issue, e.g. a game.project with dependency and a couple of lua files where the LSP doesn’t work. Also would be nice if you shared the editor logs, maybe there are some hints about why it doesn’t work.