vala-lang / vala-language-server

Code Intelligence for Vala & Genie
GNU Lesser General Public License v2.1
287 stars 41 forks source link

vls-CRITICAL ** GLib-CRITICAL ** #288

Closed MachineTrader closed 1 year ago

MachineTrader commented 1 year ago

VSCode Output: (vala-language-server:2529): vls-CRITICAL : 02:23:28.721: string_slice: assertion 'tmp3' failed (vala-language-server:2529): GLib-CRITICAL : 02:23:28.721: g_regex_match_full: assertion 'string != NULL' failed

These three statements, individually, in Genie (Json) will cause above error message to, continuously flow, in the output tab of the vala language server in vscode. The code compiles nicely and works.

    if root.is_null ()
        print "Node is null"

    if root.get_node_type () == NodeType.ARRAY
        print "Node is array"

    if root.get_node_type () == NodeType.OBJECT
        print "Node is object"

"is" instead of "==" produces the same result. The server was installed with: yay -S vala-language-server-git

Vala Language Server: 0.48.7-4-gc35dc69e
VSCodium Version: 1.76.2
OS: Linux x64 6.2.8-arch1-1
Prince781 commented 1 year ago

Hi. Do you have a full example I can use to repro?

MachineTrader commented 1 year ago

Here's a full example. It retrieves a json array of crypto currencies and their price from Binance.

[indent=0] 

uses 
    Soup
    Json

init    
    burl: string = "https://api4.binance.com/api/v3/" 
    json_string: string = http_get_request (burl,"ticker/price")    
    perform_parse (json_string)

def http_get_request(base_url:string ,url: string): string

    // Define the URL you want to make a request to 
    full_url:string = base_url + url    

    // Create a new Soup.Session object
    var session = new Soup.Session()

    // Create a new Soup.Message object and set its method and URL
    var message = new Soup.Message("GET",full_url)

    message.request_headers.append("Content-Type", "application/json")

    // Send the message and wait for the response
    session.send_message(message) 

    if message.status_code != 200
        stdout.printf ("Error: HTTP status code %d\n", (int)message.status_code)
        return ""

    var data = message.response_body.flatten().data

    data_str: string = (string)data

    // Print raw json
    print data_str

    return data_str

def perform_parse(message_body:string)  

    var parser = new Json.Parser()

    try
        parser.load_from_data((string)message_body, -1)
    except ex: Error
        stderr.printf("%s\n", ex.message)

    root: Json.Node = parser.get_root()  
    if root.is_null () 
        print "Node is null"
        return

    // Checks if we got a json array from the server
    if root.get_node_type () == NodeType.ARRAY
        arr: Json.Array = root.get_array()

        // Loop nodes in array
        for var e in arr.get_elements ()        
            var element = e.get_object ()           
            var symbol = element.get_string_member ("symbol")
            price_str:string = element.get_string_member ("price")      
            price_dbl:double = double.parse (price_str)
            print "%s %f ", symbol,price_dbl

    // Checks if we got a json object from the server   
    if root.get_node_type () == NodeType.OBJECT
        js_obj: Json.Object = root.get_object ()

        // Loop nodes in array
        for var e in js_obj.get_members ()      
            element:string = (string)e.data

            print "%s", element
Prince781 commented 1 year ago

@MachineTrader please verify the branch 288-vls-critical-glib-critical fixes your issue.

MachineTrader commented 1 year ago

Hi sorry for not getting back. I have problems building both the branch and the main. Not sure if there's something missing in my environment. It exits with this error after "Compilation succeeded - 75 warning(s)":

[157/243] Linking target subprojects/libgee/benchmark/benchmarks
ninja: build stopped: subcommand failed.
MachineTrader commented 1 year ago

Not sure what's going on, but installing with "yay -S vala-language-server-git" doesn't work any more and neither does "yay -S vala-langusge-server", I hope haven't broken my system.

The meson part works fine, but the ninja part fails:

ninja: Entering directory `build'
[1/49] Compiling Vala source ../test/testclient.vala ../src/util.vala
FAILED: test/vls-testclient.p/testclient.c test/vls-testclient.p/util.c 
valac -C --define=WITH_JSONRPC_GLIB_3_30 --target-glib=auto --enable-gobject-tracing --fatal-warnings -X -I/usr/include/gtk-3.0 --pkg gio-unix-2.0 --pkg posix --pkg libvala-0.56 --pkg jsonrpc-glib-1.0 --pkg json-glib-1.0 --pkg gee-0.8 --pkg gio-2.0 --pkg gobject-2.0 --pkg glib-2.0 --color=always --directory test/vls-testclient.p --basedir ../test ../test/testclient.vala ../src/util.vala
warning: -X has no effect when -C or --ccode is set
Compilation failed: 0 error(s), 1 warning(s)
[2/49] Generating version.vala with a custom command
Fatal: No name could be found, nothing to describe.
ninja: build stopped: subcommand failed.
Prince781 commented 1 year ago

-X -I/usr/include/gtk-3.0

That's strange. VLS doesn't depend on GTK at all. You should not be seeing any references to that. Maybe run git clean -fxd or reclone the repo?

I've tested your issue and was able to fix it in the aforementioned branch.

MachineTrader commented 1 year ago

Yes the branch seem to work. I've reinstalled my computer now to get the compiling to work though. Why I had to do that I don't know.