Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vala language server not working properly #318

Open
BhJaipal opened this issue Dec 25, 2024 · 16 comments
Open

Vala language server not working properly #318

BhJaipal opened this issue Dec 25, 2024 · 16 comments

Comments

@BhJaipal
Copy link

BhJaipal commented Dec 25, 2024

Describe the bug
Am I missing to install something?
base type null' of class MDEditor' is not an object type

My code:

public class MDEditor : GLib.Object, Gtk.Application {
	public MDEditor () {
		Gtk.Application(application_id: "org.gtk.MDEditor", flags: ApplicationFlags.FLAGS_NONE);
	}
	// ...
}

jaipal001@pop-os:~/Desktop/files/syntax-prview$ valac --verbose=med MDEditor.vala
Loaded package /usr/share/vala-0.56/vapi/glib-2.0.vapi' Loaded package /usr/share/vala-0.56/vapi/gobject-2.0.vapi'
MDEditor.vala:12.38-12.40: error: The symbol `Gtk' could not be found
12 | public class MDEditor : GLib.Object, Gtk.Application {
| ^~~
Compilation failed: 1 error(s), 0 warning(s)

Software
OS and version Pop OS 24.04:
Code editor: VSCode:
Vala Language Server installed by ubuntu binaries:
Vala version: Vala 0.56.0

@BhJaipal BhJaipal changed the title Vala language server not doing anything Vala language server not working properly Dec 25, 2024
@colinkiama
Copy link
Member

Have you read the important note in the "Editors" section?: https://github.com/vala-lang/vala-language-server?tab=readme-ov-file#editors

An important note: VLS cannot know what arguments are used for the file you are editing unless it can locate a build script, compile commands list, or shebang to analyze. (This is generally true for most language servers of compiled languages.) Before making an issue, check whether you have a build script or shebang for your file.

Also see: https://github.com/vala-lang/vala-language-server?tab=readme-ov-file#specifying-dependencies

Confirm if you're following these instructions and the issue is still happening.

@BhJaipal
Copy link
Author

I am not using any build system, I am only using a Makefile for automatic building

all:
    valac MDEditor.vala --pkg gtk4

And I have installed vscode vala extension and vala language server

But it only works for GLib and not Gtk and etc.

@ErikReider
Copy link
Contributor

ErikReider commented Dec 26, 2024

I am not using any build system, I am only using a Makefile for automatic building

all:
    valac MDEditor.vala --pkg gtk4

And I have installed vscode vala extension and vala language server

But it only works for GLib and not Gtk and etc.

Try using something like bear: 'bear -- make'

@BhJaipal
Copy link
Author

Problem is vala is only showing intellisence for GLib and no other libraries

@colinkiama
Copy link
Member

Problem is vala is only showing intellisence for GLib and no other libraries

That behaviour is normal if a project isn't setup properly to be used with Vala Language Server.

Autotools projects aren't supported by the langauge server (See "supported projects").

Please try the solution that @ErikReider suggested. It should generate a compile_commands.json that the language server will read to understand your project.

If that doesn't work, I recommend using Meson. Vala Language Server works well with Meson projects.

@BhJaipal
Copy link
Author

Problem is vala is only showing intellisence for GLib and no other libraries

That behaviour is normal if a project isn't setup properly to be used with Vala Language Server.

Autotools projects aren't supported by the langauge server (See "supported projects").

Please try the solution that @ErikReider suggested. It should generate a compile_commands.json that the language server will read to understand your project.

If that doesn't work, I recommend using Meson. Vala Language Server works well with Meson projects.

I am not using meson. Is there a default configuration you know which I can use?
And should I used meson? And how?

@colinkiama
Copy link
Member

I am not using meson. Is there a default configuration you know which I can use?
And should I used meson? And how?

After installing meson (if it's not on your system already) run this command:

meson init -l vala

It will create a project for you and provide you with instructions on how to setup a build directory and compile your project.

@BhJaipal
Copy link
Author

I am not using meson. Is there a default configuration you know which I can use?
And should I used meson? And how?

After installing meson (if it's not on your system already) run this command:

meson init -l vala

It will create a project for you and provide you with instructions on how to setup a build directory and compile your project.

And any configuration for vala vscode for gtk?

@colinkiama
Copy link
Member

The Vala extension doesn't need to be configured to work with GTK.

The meson project does. It's possible to figure it out with a bit of research.

@BhJaipal
Copy link
Author

BhJaipal commented Dec 28, 2024

But it's language server not working for gtk,
I have installed Ubuntu 22.04 vala language server package

@colinkiama
Copy link
Member

But it's language server not working for gtk,
I have installed Ubuntu 22.04 vala language server package

Again, the issue is not the language server. Vala is a compiled langauge so the language server needs to how to compile the code for it to work.

The issue is that your project isn't setup to be used with the language server.

For Meson, you just need to add gtk4 to the dependencies in the meson.build file after running the meson init command I shared earlier:

dependencies = [
    dependency('glib-2.0'),
    dependency('gobject-2.0'),
    dependency('gtk4'), # Add this line
]

@BhJaipal
Copy link
Author

It is, Compiler is working properly but language server isn't working for gtk, it is only working for GLib

@colinkiama
Copy link
Member

colinkiama commented Dec 28, 2024

How did you compile the code? With valac directly? Or did you do it using meson?

@ErikReider
Copy link
Contributor

ErikReider commented Dec 28, 2024

Follow these steps:

  1. meson init -l vala
  2. Follow the steps that @colinkiama provided to add gtk4 as a dependency (Vala language server not working properly #318 (comment))
  3. meson setup -C build
  4. meson compile -C build
  5. Restart vscode/language server

You can check out some of my projects as a reference point :)

@BhJaipal
Copy link
Author

How did you compile the code? With valac directly? Or did you do it using meson?

By valac

all:
    valac MDEditor.vala --pkg gtk4

It is working properly

@colinkiama
Copy link
Member

Ok. Follow @ErikReider's steps then let us know what happens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants