44 * @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
55 */
66
7- import { searchConfig } from "./config"
7+ import type { Documentation } from "../types"
8+ import documentation from "../documentation-data.yml"
9+ import { searchConfig } from "../config"
810import vscode from "vscode"
911
1012const enum Urls {
@@ -16,15 +18,21 @@ const enum Urls {
1618 P5jsSearchDuckDuckGo = "https://duckduckgo.com/?q=!p5+" ,
1719}
1820
19- export const openURL = async ( searchBase ?: string , url ?: string ) => {
21+ export const openURL = async ( searchBase ?: string , url ?: string ) : Promise < void > => {
2022 if ( searchBase === "open" ) {
2123 await vscode . env . openExternal ( vscode . Uri . parse ( url as string ) )
2224 } else {
2325 const { processingDocs, searchEngine} = searchConfig
2426 const searchUrl = ( ( ) : string => {
27+ let docUrl : string | undefined
28+
2529 if ( searchBase === "docs" ) {
2630 if ( ! url ) {
2731 return processingDocs === "p5js.org" ? Urls . P5jsDocs : Urls . ProcessingorgDocs
32+ } else if (
33+ ( docUrl = ( documentation as Documentation ) [ url ] ?. docUrl ) !== undefined
34+ ) {
35+ return docUrl
2836 } else if ( searchEngine === "DuckDuckGo" ) {
2937 return processingDocs === "p5js.org"
3038 ? `${ Urls . P5jsSearchDuckDuckGo } ${ url } `
@@ -42,7 +50,7 @@ export const openURL = async (searchBase?: string, url?: string) => {
4250 await vscode . env . openExternal ( vscode . Uri . parse ( searchUrl ) )
4351 }
4452
45- return true
53+ return
4654}
4755
4856// Slice and Trim
@@ -53,17 +61,8 @@ export const prepareInput = (input: string, start: number, end: number) => {
5361 return ""
5462 }
5563
56- // Slice to the selection
57- input = input . slice ( start , end )
58-
59- // Trim white space
60- input = input . trim ( )
61-
62- // Possible future addition:
63- // Check right here if valid variable/function name to search?
64-
6564 // Everything looks good by this point, so time to open a web browser!
66- return input
65+ return input . slice ( start , end ) . trim ( )
6766}
6867
6968export const openProcessingDocs = ( input : string , start : number , end : number ) => {
0 commit comments