diff --git a/.github/workflows/dev-ci.yaml b/.github/workflows/dev-ci.yaml new file mode 100644 index 00000000..a4ed3bfa --- /dev/null +++ b/.github/workflows/dev-ci.yaml @@ -0,0 +1,48 @@ +# workflow to ensure development tooling and environment is properly set up +name: Dev Environment Contingency +run-name: Dev Environment Contingency + + +permissions: + contents: write + +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + test-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + id: checkout + - name: Install Task + id: install-task + uses: arduino/setup-task@v1 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Run all tasks in the workflow + id: run-all-tasks + run: | + # Capture the list of all tasks + OUTPUT=$(task --list-all) + + # Parse the list of tasks from the output + TASKS=$(echo "$OUTPUT" | grep -oP '(?<=\* ).*(?=:)') + + # Check if TASKS variable is not empty + if [ -z "$TASKS" ]; then + echo "No tasks found." + exit 1 + fi + + # Iterate over each task and execute it + for TASK in $TASKS; do + echo "Executing task: $TASK" + task "$TASK" + echo "Completed task: $TASK" + echo "----------------------------" + done diff --git a/tools/seltabls/cmd/cmds/static.go b/tools/seltabls/cmd/cmds/static.go index 5f5a9688..aeaa1d2e 100644 --- a/tools/seltabls/cmd/cmds/static.go +++ b/tools/seltabls/cmd/cmds/static.go @@ -23,8 +23,6 @@ var ( packageName string fileName string - body string - form = huh.NewForm( huh.NewGroup( huh.NewInput(). @@ -43,6 +41,7 @@ var ( ) ) +// NewStaticCmd createa a new command for the static command. func NewStaticCmd(ctx context.Context) *cobra.Command { return &cobra.Command{ Use: "static", @@ -87,6 +86,9 @@ Statically define html given a url. PackageName: packageName, FileName: staticFileName, }) + if err != nil { + return fmt.Errorf("failed to get url: %w", err) + } err = os.WriteFile(fileName+"_test.go", []byte(content), 0644) if err != nil { return fmt.Errorf("failed to write file: %w", err) @@ -189,7 +191,10 @@ func getURLFileName(fileURL string) (string, error) { return "", fmt.Errorf("failed to create file: %w", err) } defer f.Close() - f.Write(body) + _, err = f.Write(body) + if err != nil { + return "", fmt.Errorf("failed to write file: %w", err) + } return safeFileName + ".html", nil } diff --git a/tools/seltabls/data/master/combined/queries.sql b/tools/seltabls/data/master/combined/queries.sql index 4e666d7d..3291cefe 100644 --- a/tools/seltabls/data/master/combined/queries.sql +++ b/tools/seltabls/data/master/combined/queries.sql @@ -451,4 +451,14 @@ ON CONFLICT (value) DO UPDATE SET html_id = excluded.html_id RETURNING *; + +-- name: UpsertURLOnURL :one +INSERT INTO + urls (value, html_id) +VALUES + (?, ?) +ON CONFLICT (value) +DO UPDATE + SET + html_id = excluded.html_id RETURNING id, value, html_id; /******************************************************************************/ diff --git a/tools/seltabls/data/master/queries/urls.sql b/tools/seltabls/data/master/queries/urls.sql index 2f64fb26..ca9990b8 100644 --- a/tools/seltabls/data/master/queries/urls.sql +++ b/tools/seltabls/data/master/queries/urls.sql @@ -59,4 +59,14 @@ ON CONFLICT (value) DO UPDATE SET html_id = excluded.html_id RETURNING *; + +-- name: UpsertURLOnURL :one +INSERT INTO + urls (value, html_id) +VALUES + (?, ?) +ON CONFLICT (value) +DO UPDATE + SET + html_id = excluded.html_id RETURNING id, value, html_id; /******************************************************************************/ diff --git a/tools/seltabls/pkg/analysis/textDocumentCompletion.go b/tools/seltabls/pkg/analysis/textDocumentCompletion.go index f0590391..5ef7dd1a 100644 --- a/tools/seltabls/pkg/analysis/textDocumentCompletion.go +++ b/tools/seltabls/pkg/analysis/textDocumentCompletion.go @@ -34,6 +34,7 @@ func CreateTextDocumentCompletion( urls *safe.Map[uri.URI, []string], selectors *safe.Map[uri.URI, []master.Selector], ) (response *lsp.TextDocumentCompletionResponse, err error) { + log.Debugf("CreateTextDocumentCompletion") select { case <-ctx.Done(): return nil, fmt.Errorf("context cancelled: %w", ctx.Err()) diff --git a/tools/seltabls/pkg/http/browser.go b/tools/seltabls/pkg/http/browser.go deleted file mode 100644 index 2c88a9ba..00000000 --- a/tools/seltabls/pkg/http/browser.go +++ /dev/null @@ -1,27 +0,0 @@ -package http - -import ( - "fmt" - "log" - "os/exec" - "runtime" -) - -// OpenBrowser opens the default browser with the given url -func OpenBrowser(url string) { - var err error - switch runtime.GOOS { - case "linux": - err = exec.Command("xdg-open", url).Start() - case "windows": - err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url). - Start() - case "darwin": - err = exec.Command("open", url).Start() - default: - err = fmt.Errorf("unsupported platform") - } - if err != nil { - log.Fatal(err) - } -} diff --git a/tools/seltabls/pkg/lsp/message.go b/tools/seltabls/pkg/lsp/message.go index e94d53dc..1e100842 100644 --- a/tools/seltabls/pkg/lsp/message.go +++ b/tools/seltabls/pkg/lsp/message.go @@ -5,6 +5,7 @@ import ( "github.com/conneroisu/seltabl/tools/seltabls/pkg/lsp/methods" "github.com/conneroisu/seltabl/tools/seltabls/pkg/safe" + "go.lsp.dev/protocol" ) var ( @@ -34,7 +35,7 @@ type Response struct { // Method returns the method for the response func (r Response) Method() methods.Method { - return methods.MethodInitialize + return protocol.MethodInitialize } // Notification is a notification from a LSP diff --git a/tools/seltabls/pkg/parsers/selectors.go b/tools/seltabls/pkg/parsers/selectors.go index 607b99c2..4c2f831f 100644 --- a/tools/seltabls/pkg/parsers/selectors.go +++ b/tools/seltabls/pkg/parsers/selectors.go @@ -24,9 +24,7 @@ func GetAllSelectors(doc *goquery.Document) ([]string, error) { str := getSelectorsFromSelection(s) if str != empty { if !contains(strs, str) { - if doc.Find(str).Length() == 0 { - strs = append(strs, str) - } + strs = append(strs, str) } } }) @@ -48,7 +46,7 @@ func getSelectorsFromSelection(s *goquery.Selection) string { currentSelector := singleSelector(s) // Combine the parent and current selectors if parentSelector != empty && currentSelector != "" && parentSelector != currentSelector { - return parentSelector + currentSelector + return parentSelector + childsep + currentSelector } else if parentSelector != empty && currentSelector == "" { return parentSelector } @@ -99,9 +97,9 @@ func GetSelectors( if err != nil { return nil, fmt.Errorf("failed to insert html: %w", err) } - URL, err := db.Queries.InsertURL( + URL, err := db.Queries.UpsertURL( ctx, - master.InsertURLParams{Value: url, HtmlID: HTML.ID}, + master.UpsertURLParams{Value: url, HtmlID: HTML.ID}, ) if err != nil { return nil, fmt.Errorf("failed to insert url: %w", err) diff --git a/tools/seltabls/pkg/safe/map.go b/tools/seltabls/pkg/safe/map.go index 5af49bd5..edc8d907 100644 --- a/tools/seltabls/pkg/safe/map.go +++ b/tools/seltabls/pkg/safe/map.go @@ -68,6 +68,7 @@ func (sm *Map[K, V]) String() string { return b.String() } +// limitString limits the length of a string to the given limit. func limitString(s string, limit int) string { if len(s) > limit { return s[:limit] + "..."