vscode-db2i icon indicating copy to clipboard operation
vscode-db2i copied to clipboard

Go to Definition support

Open worksofliam opened this issue 1 year ago • 1 comments

Enables Go to Definition and Peek Definition, which under the hood uses GENERATE_SQL.

It would be nicer with the formatter, but that can come later since we don't have that yet.

worksofliam avatar Sep 18 '24 19:09 worksofliam

👋 A new build is available for this PR based on 854d70bd80ed8a36bcf3e668efdd48053f200323.

github-actions[bot] avatar Sep 18 '24 19:09 github-actions[bot]

@julesyan is this another you can take a look at when you have a mo?

worksofliam avatar Mar 15 '25 21:03 worksofliam

Yes I can test in a couple hours

julesyan avatar Mar 15 '25 21:03 julesyan

When using NAMING *SQL and SET SCHEMA, peek went to the wrong table.

-- Create a table with a polygon column and insert several polygons that represent different New York City Parks
set schema coolstuff;
drop table if exists sample_parks;
CREATE TABLE sample_parks (park_name VARCHAR(50), geometry QSYS2.ST_POLYGON);
INSERT INTO sample_parks (park_name, geometry) VALUES
  ('Central Park', QSYS2.ST_POLYGON('polygon((-73.9817 40.7682, -73.9581 40.8005, -73.9495 40.7968, -73.9732 40.7644, -73.9817 40.7682))')),
  ('Washington Square Park', QSYS2.ST_POLYGON('polygon((-73.9995 40.7310, -73.9986 40.7321, -73.9957 40.7307, -73.9966 40.7297, -73.9995 40.7310))'));

-- Find the maximum and minimum x and y coordinate for various New York City parks
SELECT park_name, 
       QSYS2.ST_MAXX(geometry) AS max_x,
       QSYS2.ST_MAXY(geometry) AS max_y,
       QSYS2.ST_MINX(geometry) AS min_x,
       QSYS2.ST_MINY(geometry) AS min_y
 FROM sample_parks;

image

forstie avatar Mar 16 '25 16:03 forstie

To do for me:

  • If system naming is used, use the library list.
  • If SQL naming is used, use the current library/schema.
  • If a qualified name is used, use that

worksofliam avatar Mar 16 '25 17:03 worksofliam

Question, when you use peek it opens a whole new file, is there any way to do peek without a new file? Or at least close said file when the peek is closed? Because if i do peek often enough, it is tedious to close a bunch of unsaved files (I did 16 peeks and it was annoying to close)

julesyan avatar Mar 17 '25 00:03 julesyan

@julesyan I checked, but sadly in this particular instance it's not possible to stop the tab from coming up.

It's because the source is temporary because we are generating it from GENERATE_SQL. If the source actually existed on a file system somewhere, then the tab would not show up, but that's not the case here.

worksofliam avatar Mar 17 '25 01:03 worksofliam

@worksofliam Peek doesn't handle delimited named schemas or delimited named tables or views.

create schema "annoying"; CREATE TABLE "annoying"."annoyingly123" for system name "annoy1" (park_name VARCHAR(50), geometry QSYS2.ST_POLYGON); CREATE TABLE qgpl."annoyingly123" for system name "annoy1" (foo integer);

select * from "annoyingly123"; select * from "annoy1"; image

forstie avatar Mar 17 '25 17:03 forstie

Peek isn't working for this situation:

CREATE SCHEMA "CaMel"; CREATE TABLE "CaMel"."CoWt" ( "cLo" FOR COLUMN CLO__00001 INTEGER DEFAULT NULL )
RCDFMT "CoWt" ;

-- then try to peek on "CoWt" SELECT * FROM "CaMel"."CoWt"

forstie avatar Apr 28 '25 19:04 forstie

also, it seems that peek is using the LIBL list all the time when I use SQL naming, that doesn't make sense I would expect the current schema to rule supreme for unqualified tables in a query and SQL naming

forstie avatar Apr 28 '25 19:04 forstie

Here's a recreate of the NAMING(*SQL) not working for PEEK. As the example shows, NAMING(*SQL) works fine for the query.

-- use naming *SQL on your connection create schema notinlibl; CREATE TABLE notinlibl.baset(foo integer); insert into notinlibl.baset values(5);

set schema notinlibl; select * from baset;

forstie avatar Apr 28 '25 21:04 forstie

This test isn't peek'ing for me

create schema "annoying2" for schema "annoy2"; CREATE TABLE "annoying2"."annoyingly123" for system name "annoy1" (park_name VARCHAR(50), geometry QSYS2.ST_POLYGON); CREATE view "annoying2"."annoyingly1234" for system name "annoy14" as select 1 as foo from qsys2.qsqptabl; set schema "annoying2"; -- peek does not work for the following 4 queries - SQL naming select * from "annoyingly123"; select * from "annoy1"; select * from "annoy14"; select * from "annoyingly1234";

forstie avatar Apr 30 '25 12:04 forstie