After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 790846 - Some improvements to the JS code indexer
Some improvements to the JS code indexer
Status: RESOLVED FIXED
Product: gnome-builder
Classification: Other
Component: plugins
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME Builder Maintainers
GNOME Builder Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-11-26 10:42 UTC by Giovanni Campagna
Modified: 2017-12-04 00:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gjs_symbols: don't choke on toplevel destructuring assingments (1.16 KB, patch)
2017-11-26 10:42 UTC, Giovanni Campagna
committed Details | Review
gjs_symbols: be compatible with CommonJS too (2.67 KB, patch)
2017-11-26 10:42 UTC, Giovanni Campagna
committed Details | Review
gjs_symbols: don't ignore files in node_modules/ (1.13 KB, patch)
2017-11-26 10:42 UTC, Giovanni Campagna
committed Details | Review
IdeRunner: don't override the CWD of the launcher (1.17 KB, patch)
2017-11-27 01:47 UTC, Giovanni Campagna
committed Details | Review
IdeBuildTarget: add get_cwd() (4.11 KB, patch)
2017-11-27 01:47 UTC, Giovanni Campagna
committed Details | Review
npm: add BuildTargetProvider (5.01 KB, patch)
2017-11-27 01:47 UTC, Giovanni Campagna
committed Details | Review
IdeBuildTarget: add get_language() (4.67 KB, patch)
2017-11-27 01:47 UTC, Giovanni Campagna
committed Details | Review
GdbDebugger: chain up properly from dispose (977 bytes, patch)
2017-11-27 01:47 UTC, Giovanni Campagna
committed Details | Review
IdeDebugManager: check the programming language to see if the debugger is compatible (8.88 KB, patch)
2017-11-27 01:47 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2017-11-26 10:42:34 UTC
It's great to have a gjs code indexer, and it just needs a little help to
make it a nice node.js code indexer.
Comment 1 Giovanni Campagna 2017-11-26 10:42:39 UTC
Created attachment 364418 [details] [review]
gjs_symbols: don't choke on toplevel destructuring assingments

A destructuring assignment Pattern does not have a 'name' property,
which would crash the symbol extractor and abort everything.
Comment 2 Giovanni Campagna 2017-11-26 10:42:42 UTC
Created attachment 364419 [details] [review]
gjs_symbols: be compatible with CommonJS too

Recognize the Common JS idioms:

"const Foo = require(...)" to import a module
"module.exports = class Foo { ... }" to declare the main class of
a module
Comment 3 Giovanni Campagna 2017-11-26 10:42:44 UTC
Created attachment 364420 [details] [review]
gjs_symbols: don't ignore files in node_modules/

The code indexer already ignores all directories that are gitignored.
If node_modules/ is not gitignored, it means it contains files that
the developer cares about.
Comment 4 Christian Hergert 2017-11-26 10:46:37 UTC
Review of attachment 364418 [details] [review]:

LGTM
Comment 5 Christian Hergert 2017-11-26 10:47:14 UTC
Review of attachment 364420 [details] [review]:

LGTM
Comment 6 Patrick Griffis (tingping) 2017-11-26 10:49:02 UTC
Review of attachment 364420 [details] [review]:

> The code indexer already ignores all directories that are gitignored.
If node_modules/ is not gitignored, it means it contains files that
the developer cares about.

I still expect this to lead to complaints.

If you add the directory before ignoring it the indexer will pick it all up and no UI is exposed to easily clear it and some users might just not be familiar with git. As I'm sure you know indexing this directory can literally be indexing *hundreds* of projects and *thousands* of files. I'm just not sure that is something to do lightly?
Comment 7 Christian Hergert 2017-11-26 10:53:30 UTC
Review of attachment 364419 [details] [review]:

Excellent, thanks!
Comment 8 Giovanni Campagna 2017-11-26 20:04:10 UTC
(In reply to Patrick Griffis (tingping) from comment #6)
> Review of attachment 364420 [details] [review] [review]:
> 
> If you add the directory before ignoring it the indexer will pick it all up
> and no UI is exposed to easily clear it and some users might just not be
> familiar with git. As I'm sure you know indexing this directory can
> literally be indexing *hundreds* of projects and *thousands* of files. I'm
> just not sure that is something to do lightly?

I disagree with the point that people might unfamiliar with git.
Developers have been using VCSs for decade, and all the good VCSs (all the way back to SVN) have some concept of ignoring files.
I expect the users of Builder to understand that.

On the other hand, I take your point that for brand new projects, close to the initial commit, node_modules/ might not be in gitignore yet.
(Same thing if some modules are ignored and some aren't, and later you add a new module)
If that happens, Builder will index those files, resulting in a lot of unremovable garbage in the index.

Would it be a good idea instead to ignore both gitignored and untracked files?

At a later time, if it turns out the new file is source and not dependency, the developer will add it to git and the indexer will pick it up.
Comment 9 Giovanni Campagna 2017-11-27 01:47:19 UTC
Created attachment 364473 [details] [review]
IdeRunner: don't override the CWD of the launcher

It is set a few lines above by real_create_launcher()
Comment 10 Giovanni Campagna 2017-11-27 01:47:23 UTC
Created attachment 364474 [details] [review]
IdeBuildTarget: add get_cwd()

Some build systems (notably, npm), insist that their build targets
be run in a specific working directory, or they'll misbehave.

To allow BuildTargets and BuildTargetProviders specify that,
introduce a vfunc get_cwd(). If this vfunc returns any non-NULL
value, IdeRuntime uses it to set the cwd of the created IdeRunner.
Comment 11 Giovanni Campagna 2017-11-27 01:47:26 UTC
Created attachment 364475 [details] [review]
npm: add BuildTargetProvider

Which allows one to specify what to run in package.json, as the
"start" script (a node.js convention), and then uses npm to run it.
Comment 12 Giovanni Campagna 2017-11-27 01:47:29 UTC
Created attachment 364476 [details] [review]
IdeBuildTarget: add get_language()

Add a way to find the programming language of a build target.
This will be used to weed out incompatible debuggers, profiling
tools, etc.

Cargo build targets are changed to return rust, NPM to return JS.
Similarly, a future Cabal integration should say Haskell, Maven or ANT
should say Java, etc.

For now, automake, meson and cmake return "asm" (native code),
because it's annoying to find if the build target is built from C,
C++, Vala or Fortran, and it does not matter too much because gdb
and valgrind can deal with it.
Comment 13 Giovanni Campagna 2017-11-27 01:47:32 UTC
Created attachment 364477 [details] [review]
GdbDebugger: chain up properly from dispose

If you chain up twice to finalize, you're going to have a bad time.
Comment 14 Giovanni Campagna 2017-11-27 01:47:35 UTC
Created attachment 364478 [details] [review]
IdeDebugManager: check the programming language to see if the debugger is compatible

Make it possible to retrieve the IdeBuildTarget from the IdeRunner,
and use it to retrieve the programming language of the program
being run. Compare it to the list of languages claimed by the
debugger to see if the debugger is compatible.

Tested with npm on host (correctly claims no debugger is available)
and meson on flatpak (correctly starts gdb)
Comment 15 Giovanni Campagna 2017-11-27 01:48:13 UTC
While we're here, I'm adding some more JS improvements (mostly nodejs related), in the area of running and debugging.
Comment 16 Christian Hergert 2017-11-27 02:34:41 UTC
Review of attachment 364473 [details] [review]:

sure
Comment 17 Christian Hergert 2017-11-27 02:36:57 UTC
Review of attachment 364474 [details] [review]:

couple real quick fixes, then fine to push

::: src/libide/buildsystem/ide-build-target.c
@@ -125,0 +132,13 @@
+
+/**
+ * ide_build_target_get_cwd:
... 10 more ...

(nullable)

@@ -125,0 +132,18 @@
+
+/**
+ * ide_build_target_get_cwd:
... 15 more ...

Remove extraneous space

@@ +148,3 @@
+gchar *
+ide_build_target_get_cwd (IdeBuildTarget       *self)
+{

g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);

::: src/libide/runtimes/ide-runtime.c
@@ -171,2 +171,3 @@
   g_auto(GStrv) argv = NULL;
   const gchar *slash;
+  g_autofree gchar *cwd;

We always initialize autoptr/autofree variables to NULL in the Builder codebase.
Comment 18 Christian Hergert 2017-11-27 02:41:47 UTC
Review of attachment 364475 [details] [review]:

Seems like a useful addition. Need to drop the use of lambda then fine to push.

::: src/plugins/npm/npm_plugin.py
@@ -109,0 +111,44 @@
+
+# The scripts used by the npm build system during build
+# we don't want to include these as build target
... 41 more ...

Would sort of prefer to have a variable defined than script[3:] repeated

@@ +205,3 @@
+
+        project_file = context.get_project_file()
+        project_file.load_contents_async(cancellable, lambda *x: self._on_package_json_loaded(task, *x))

We don't use lambda in the Builder code-base because it sometimes causes runtime memory reference issues that are super hard to track down. So needs to be a callback function.
Comment 19 Christian Hergert 2017-11-27 02:43:54 UTC
Review of attachment 364476 [details] [review]:

Nice work, we can use this with sysprof once we get that spidermonkey profiler merged too. Couple small nits then good to push.

::: src/libide/buildsystem/ide-build-target.c
@@ +182,3 @@
+ */
+gchar *
+ide_build_target_get_language (IdeBuildTarget       *self)

remove extra spacing

@@ +184,3 @@
+ide_build_target_get_language (IdeBuildTarget       *self)
+{
+  return IDE_BUILD_TARGET_GET_IFACE (self)->get_language (self);

Add g_return_val_if_fail (IDE_IS_BUILD_TARGET (self), NULL);

::: src/libide/buildsystem/ide-build-target.h
@@ +54,3 @@
 gchar     *ide_build_target_get_cwd               (IdeBuildTarget       *self);
 IDE_AVAILABLE_IN_3_28
+gchar     *ide_build_target_get_language               (IdeBuildTarget       *self);

Fix alignment
Comment 20 Christian Hergert 2017-11-27 02:44:12 UTC
Review of attachment 364477 [details] [review]:

Yuck. Thanks for finding this
Comment 21 Christian Hergert 2017-11-27 02:50:20 UTC
Review of attachment 364478 [details] [review]:

Looks like you're headed down the right path, couple fixes before pushing

::: src/libide/debugger/ide-debug-manager.c
@@ +34,3 @@
 #include "plugins/ide-extension-util.h"
 #include "runner/ide-runner.h"
+#include "buildsystem/ide-build-target.h"

Alphabetically sort

@@ -702,0 +703,14 @@
+static gboolean
+debugger_supports_language (PeasPluginInfo *plugin_info,
+                            const gchar    *language)
... 11 more ...

We get to use modern C features for Builder, so

for (guint i =

@@ -719,0 +743,5 @@
+      IdeBuildTarget *build_target = ide_runner_get_build_target (lookup->runner);
+
+      if (build_target != NULL)
... 2 more ...

* next to variable, not base-type, so "g_autofree gchar *language = ..."

::: src/libide/runner/ide-runner.c
@@ +684,3 @@
+   * that will be launched, such as what programming language it uses,
+   * or whether it's a graphical application, a command line tool or a test
+   * program.

Since: 3.28

@@ +687,3 @@
+   */
+  properties [PROP_BUILD_TARGET] =
+    g_param_spec_boolean ("build-target",

g_param_spec_object

@@ +690,3 @@
+                          "Build Target",
+                          "Build Target",
+                          FALSE,

IDE_TYPE_BUILD_TARGET

@@ +1423,3 @@
+ *
+ * Returns: (nullable) (transfer none): The %IdeBuildTarget associated with this %IdeRunner, or %NULL.
+ *   See IdeRunner:build-target for details.

#IdeRunner:build-target

@@ +1455,3 @@
+
+  if (g_set_object (&priv->build_target, build_target))
+    {

No braces necessary

::: src/plugins/flatpak/gbp-flatpak-runtime.c
@@ -286,3 +287,4 @@
     binary_name = get_binary_name (self, build_target);
 
-  return IDE_RUNNER (gbp_flatpak_runner_new (context, build_path, binary_name));
+  runner = IDE_RUNNER (gbp_flatpak_runner_new (context, build_path, binary_name));
+  ide_runner_set_build_target (runner, build_target);

if (build_target != NULL) ?
Comment 22 Christian Hergert 2017-11-27 05:14:27 UTC
Comment on attachment 364477 [details] [review]
GdbDebugger: chain up properly from dispose

Attachment 364477 [details] pushed as c15bf32 - GdbDebugger: chain up properly from dispose
Comment 23 Giovanni Campagna 2017-12-04 00:23:06 UTC
All comments were addressed.

Attachment 364418 [details] pushed as 4b0cf06 - gjs_symbols: don't choke on toplevel destructuring assingments
Attachment 364419 [details] pushed as 48af8a9 - gjs_symbols: be compatible with CommonJS too
Attachment 364420 [details] pushed as 49511a8 - gjs_symbols: don't ignore files in node_modules/
Attachment 364473 [details] pushed as f1fdc4d - IdeRunner: don't override the CWD of the launcher
Attachment 364474 [details] pushed as e891c08 - IdeBuildTarget: add get_cwd()
Attachment 364475 [details] pushed as eea6aa8 - npm: add BuildTargetProvider
Attachment 364476 [details] pushed as b2e1d33 - IdeBuildTarget: add get_language()
Attachment 364478 [details] pushed as 81410f2 - IdeDebugManager: check the programming language to see if the debugger is compatible