ashish10alex / vscode-dataform-tools

Dataform tools - a vscode extension
https://marketplace.visualstudio.com/items?itemName=ashishalex.dataform-lsp-vscode
MIT License
20 stars 4 forks source link

feat: make finding the position of js variable / functions more robust #55

Closed ashish10alex closed 1 week ago

ashish10alex commented 1 week ago

This PR

related to https://github.com/ashish10alex/vscode-dataform-tools/pull/51

Tested against following input .Updated with scenarios which would have previously failed

config {
  type: 'table'
}

/*
create a parameters.js file in the includes directory and add 
getDateMonthsBefore function

function getDateMonthsBefore(date, months) {
  date.setMonth(date.getMonth() + months);
  let date_string = date.toISOString().split('T')[0];
  date_string = `'${date_string}'`;
  return date_string

}
*/

js {
  let some_mod = require("includes/parameters.js")
  const team = "barcelona"
  const six_months_ago_from_now = some_mod.getDateMonthsBefore(new Date(), -6)
  const four_months_ago_from_now = some_mod.getDateMonthsBefore(new Date(), -6)
  const some_month = "january"
  const some_number = 11;
  const barcelona = "a team"
  let some_coniditon = true;
  let another_coniditon = true;
  var some_floating_points = 9.4;
}

select 
  *
, ${six_months_ago_from_now}  some_time_1
, ${four_months_ago_from_now}  some_time_2
, ${some_number}  some_number
, ${some_coniditon}  some_condition
, ${another_coniditon}  another_coniditon
, ${some_floating_points}  some_floating_points
, "${some_month}"  some_month 
, ${some_mod.getDateMonthsBefore(new Date(), -4)} date_wt_func
, ${parameters.OXRC_DATA_STARTING_POINT}  as date_from_file
, "${barcelona}" as some_team
FROM ${ref("0100_CALENDAR")}
HampB commented 1 week ago

Nice! The search seems to work as intended now. I'll merge this PR