diff --git a/pkg/builder/builder_suite_test.go b/pkg/builder/builder_suite_test.go index c2c3964d2..343849a2f 100644 --- a/pkg/builder/builder_suite_test.go +++ b/pkg/builder/builder_suite_test.go @@ -21,7 +21,7 @@ import ( . "github.com/onsi/gomega" ) -func TestOci(t *testing.T) { +func TestBuilder(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Builder Suite") } diff --git a/pkg/vscode/types.go b/pkg/editor/vscode/types.go similarity index 100% rename from pkg/vscode/types.go rename to pkg/editor/vscode/types.go diff --git a/pkg/editor/vscode/vscode_suite_test.go b/pkg/editor/vscode/vscode_suite_test.go new file mode 100644 index 000000000..5c378f419 --- /dev/null +++ b/pkg/editor/vscode/vscode_suite_test.go @@ -0,0 +1,27 @@ +// Copyright 2022 The MIDI Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package vscode + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestVSCode(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "VS Code Suite") +} diff --git a/pkg/editor/vscode/vscode_test.go b/pkg/editor/vscode/vscode_test.go new file mode 100644 index 000000000..94a52def3 --- /dev/null +++ b/pkg/editor/vscode/vscode_test.go @@ -0,0 +1,81 @@ +// Copyright 2022 The MIDI Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package vscode + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("Visual Studio Code", func() { + Describe("Plugin", func() { + It("should be able to parse", func() { + tcs := []struct { + name string + expectedExtension string + expectedVersion string + expectedPublisher string + expectedErr bool + }{ + { + name: "ms-python.python-2021.12.1559732655", + expectedPublisher: "ms-python", + expectedExtension: "python", + expectedVersion: "2021.12.1559732655", + expectedErr: false, + }, + { + name: "ms-vscode.cpptools-1.7.1", + expectedPublisher: "ms-vscode", + expectedExtension: "cpptools", + expectedVersion: "1.7.1", + expectedErr: false, + }, + { + name: "github.copilot-1.12.5517", + expectedPublisher: "github", + expectedExtension: "copilot", + expectedVersion: "1.12.5517", + expectedErr: false, + }, + { + name: "dbaeumer.vscode-eslint-1.1.1", + expectedPublisher: "dbaeumer", + expectedExtension: "vscode-eslint", + expectedVersion: "1.1.1", + expectedErr: false, + }, + { + name: "test", + expectedErr: true, + }, + { + name: "test.test", + expectedErr: true, + }, + } + for _, tc := range tcs { + p, err := ParsePlugin(tc.name) + if tc.expectedErr { + Expect(err).To(HaveOccurred()) + } else { + Expect(err).ToNot(HaveOccurred()) + Expect(p.Publisher).To(Equal(tc.expectedPublisher)) + Expect(p.Extension).To(Equal(tc.expectedExtension)) + Expect(p.Version).To(Equal(tc.expectedVersion)) + } + } + }) + }) +}) diff --git a/pkg/vscode/vsocde.go b/pkg/editor/vscode/vsocde.go similarity index 89% rename from pkg/vscode/vsocde.go rename to pkg/editor/vscode/vsocde.go index 8ba4f1060..7d92f2740 100644 --- a/pkg/vscode/vsocde.go +++ b/pkg/editor/vscode/vsocde.go @@ -96,10 +96,19 @@ func (c generalClient) DownloadOrCache(p Plugin) error { return nil } -func ParsePlugin(p string) (Plugin, error) { +func ParsePlugin(p string) (*Plugin, error) { indexPublisher := strings.Index(p, ".") + if indexPublisher == -1 { + return nil, errors.New("invalid publisher") + } publisher := p[:indexPublisher] - indexExtension := strings.Index(p[indexPublisher:], "-") + indexPublisher + + indexExtension := strings.LastIndex(p[indexPublisher:], "-") + if indexExtension == -1 { + return nil, errors.New("invalid extension") + } + + indexExtension = indexPublisher + indexExtension extension := p[indexPublisher+1 : indexExtension] version := p[indexExtension+1:] logrus.WithFields(logrus.Fields{ @@ -107,7 +116,7 @@ func ParsePlugin(p string) (Plugin, error) { "extension": extension, "version": version, }).Debug("vscode plugin is parsed") - return Plugin{ + return &Plugin{ Publisher: publisher, Extension: extension, Version: version, diff --git a/pkg/lang/ir/graph.go b/pkg/lang/ir/graph.go index 0becc2dc7..31539a335 100644 --- a/pkg/lang/ir/graph.go +++ b/pkg/lang/ir/graph.go @@ -24,9 +24,10 @@ import ( "github.com/moby/buildkit/client/llb" "github.com/sirupsen/logrus" "github.com/spf13/viper" + + "github.com/tensorchord/MIDI/pkg/editor/vscode" "github.com/tensorchord/MIDI/pkg/flag" "github.com/tensorchord/MIDI/pkg/shell" - "github.com/tensorchord/MIDI/pkg/vscode" ) func NewGraph() *Graph { diff --git a/pkg/lang/ir/interface.go b/pkg/lang/ir/interface.go index bab30910c..9ba86ed6d 100644 --- a/pkg/lang/ir/interface.go +++ b/pkg/lang/ir/interface.go @@ -3,7 +3,7 @@ package ir import ( "errors" - "github.com/tensorchord/MIDI/pkg/vscode" + "github.com/tensorchord/MIDI/pkg/editor/vscode" ) func Base(os, language string) { @@ -30,7 +30,7 @@ func VSCodePlugins(plugins []string) error { if err != nil { return err } - DefaultGraph.VSCodePlugins = append(DefaultGraph.VSCodePlugins, plugin) + DefaultGraph.VSCodePlugins = append(DefaultGraph.VSCodePlugins, *plugin) } return nil } diff --git a/pkg/lang/ir/types.go b/pkg/lang/ir/types.go index 63b1ac3bd..bc8a6f5ea 100644 --- a/pkg/lang/ir/types.go +++ b/pkg/lang/ir/types.go @@ -15,7 +15,7 @@ package ir import ( - "github.com/tensorchord/MIDI/pkg/vscode" + "github.com/tensorchord/MIDI/pkg/editor/vscode" ) // A Graph contains the state,