Fork me on GitHub
#joyride
<
2023-11-08
>
Dave19:11:39

I am confused about how to import extensions api’s. I am not very well versed in VSCode Extensions, but there seems to be some inconsistent behavior between the (:require) and getExtension that I find a bit confusing. I am trying to use Joyride to poke about the functions of different extensions, and to create some basic user scripts to automate certain tasks. This code shows the output of one of my scripts trying to import the Splunk Extension for VSCode. Note that splunk-api doesn’t work, while splunk-ext does.

(ns splunk-joyride
  (:require ["vscode" :as vscode]
            [joyride.core :as joyride]
            ["" :as splunk-api]))
;; => nil

(def splunk-ext (vscode/extensions.getExtension "Splunk.splunk"))
;; => #'splunk-joyride/splunk-ext

(js-keys vscode)
;; => #js ["version" "ai" "authentication" "commands" "comments" "chat" "debug" "env" "extensions" "interactive" "l10n" "languages" "notebooks" "scm" "speech" "tasks" "tests" "window" "workspace" "Breakpoint" "TerminalOutputAnchor" "ChatAgentResultFeedbackKind" "ChatMessage" "ChatMessageRole" "ChatVariableLevel" "CallHierarchyIncomingCall" "CallHierarchyItem" "CallHierarchyOutgoingCall" "CancellationError" "CancellationTokenSource" "CandidatePortSource" "CodeAction" "CodeActionKind" "CodeActionTriggerKind" "CodeLens" "Color" "ColorInformation" "ColorPresentation" "ColorThemeKind" "CommentMode" "CommentState" "CommentThreadCollapsibleState" "CommentThreadState" "CompletionItem" "CompletionItemKind" "CompletionItemTag" "CompletionList" "CompletionTriggerKind" "ConfigurationTarget" "CustomExecution" ...]

(js-keys splunk-ext)
;; => #js ["id" "extensionUri" "extensionPath" "packageJSON" "extensionKind" "isFromDifferentExtensionHost"]

(js-keys splunk-api)
;; => Could not resolve symbol: splunk-api

pez20:11:21

Hi! You should be able to evaluate splunk-api

Dave20:11:31

It doesn’t seem to resolve.

splunk-api
;; => Could not resolve symbol: splunk-api
I am not sure what to do to troubleshoot.

pez20:11:09

It could be something with when that extension activates. Let me try a thing…

pez20:11:32

I can’t get it to work. Starting to suspect it doesn’t provide an API. Although, I had expected something like an empty object in that case… Do you know if it has an API?

Dave20:11:17

I don’t to be honest. That’s why I wanted to poke around with Joyride. How does one find out if a VSCode extension has an API? Source is here if you are curious: https://github.com/splunk/vscode-extension-splunk

pez21:11:28

It should return an object from it’s activate function. Splunk doesn’t, if I have found the correct activate function: https://github.com/splunk/vscode-extension-splunk/blob/master/out/extension.js#L272

pez21:11:44

But it contributes 16 commands, which is a form of API too, so you might be able to make it do whatever it is you wanted to make it do with those.