Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devit #81

Merged
merged 7 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/dev-ci.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 8 additions & 3 deletions tools/seltabls/cmd/cmds/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
packageName string
fileName string

body string

form = huh.NewForm(
huh.NewGroup(
huh.NewInput().
Expand All @@ -43,7 +41,8 @@
)
)

// NewStaticCmd createa a new command for the static command.
func NewStaticCmd(ctx context.Context) *cobra.Command {

Check warning on line 45 in tools/seltabls/cmd/cmds/static.go

View check run for this annotation

Codeac.io / Codeac Code Quality

unused-parameter

parameter 'ctx' seems to be unused, consider removing or renaming it as _
return &cobra.Command{
Use: "static",
Short: "Statically define html given a url.",
Expand Down Expand Up @@ -87,6 +86,9 @@
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)
Expand Down Expand Up @@ -189,7 +191,10 @@
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
}
10 changes: 10 additions & 0 deletions tools/seltabls/data/master/combined/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/******************************************************************************/
10 changes: 10 additions & 0 deletions tools/seltabls/data/master/queries/urls.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/******************************************************************************/
1 change: 1 addition & 0 deletions tools/seltabls/pkg/analysis/textDocumentCompletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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())
Expand Down Expand Up @@ -102,19 +103,19 @@
Deprecated: false,
Kind: protocol.CompletionItemKindValue,
InsertTextFormat: protocol.InsertTextFormatPlainText,
InsertTextMode: protocol.InsertTextModeAsIs,
}
if len(item.Label) > maxCompletionLabelLength {
item.InsertText = item.Label
item.Label = hiddenText + item.Label[len(item.Label)-maxCompletionLabelLength-len(hiddenText):]
}
response.Result = append(
response.Result,
item,
)
}
case parsers.StateAfterColon:
for _, selector := range *selectors {

Check warning on line 118 in tools/seltabls/pkg/analysis/textDocumentCompletion.go

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 12 lines is too similar to tools/seltabls/pkg/analysis/textDocumentCompletion.go:134
item := protocol.CompletionItem{
Deprecated: false,
Detail: fmt.Sprintf(
Expand All @@ -130,19 +131,19 @@
Label: fmt.Sprintf(
`"%s"`,
selector.Value,
),
}
if len(item.Label) > maxCompletionLabelLength {
item.InsertText = item.Label
item.Label = hiddenText + item.Label[len(item.Label)-maxCompletionLabelLength-len(hiddenText):]
}
response.Result = append(
response.Result,
item,
)
}
default:
return nil, nil

Check warning on line 146 in tools/seltabls/pkg/analysis/textDocumentCompletion.go

View check run for this annotation

Codeac.io / Codeac Code Quality

CodeDuplication

This block of 12 lines is too similar to tools/seltabls/pkg/analysis/textDocumentCompletion.go:106
}
return response, nil
}
Expand Down
27 changes: 0 additions & 27 deletions tools/seltabls/pkg/http/browser.go

This file was deleted.

3 changes: 2 additions & 1 deletion tools/seltabls/pkg/lsp/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions tools/seltabls/pkg/parsers/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/seltabls/pkg/safe/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] + "..."
Expand Down
Loading