find.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. package opencode
  3. import (
  4. "context"
  5. "net/http"
  6. "net/url"
  7. "github.com/sst/opencode-sdk-go/internal/apijson"
  8. "github.com/sst/opencode-sdk-go/internal/apiquery"
  9. "github.com/sst/opencode-sdk-go/internal/param"
  10. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  11. "github.com/sst/opencode-sdk-go/option"
  12. )
  13. // FindService contains methods and other services that help with interacting with
  14. // the opencode API.
  15. //
  16. // Note, unlike clients, this service does not read variables from the environment
  17. // automatically. You should not instantiate this service directly, and instead use
  18. // the [NewFindService] method instead.
  19. type FindService struct {
  20. Options []option.RequestOption
  21. }
  22. // NewFindService generates a new service that applies the given options to each
  23. // request. These options are applied after the parent client's options (if there
  24. // is one), and before any request-specific options.
  25. func NewFindService(opts ...option.RequestOption) (r *FindService) {
  26. r = &FindService{}
  27. r.Options = opts
  28. return
  29. }
  30. // Find files
  31. func (r *FindService) Files(ctx context.Context, query FindFilesParams, opts ...option.RequestOption) (res *[]string, err error) {
  32. opts = append(r.Options[:], opts...)
  33. path := "find/file"
  34. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  35. return
  36. }
  37. // Find workspace symbols
  38. func (r *FindService) Symbols(ctx context.Context, query FindSymbolsParams, opts ...option.RequestOption) (res *[]Symbol, err error) {
  39. opts = append(r.Options[:], opts...)
  40. path := "find/symbol"
  41. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  42. return
  43. }
  44. // Find text in files
  45. func (r *FindService) Text(ctx context.Context, query FindTextParams, opts ...option.RequestOption) (res *[]FindTextResponse, err error) {
  46. opts = append(r.Options[:], opts...)
  47. path := "find"
  48. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  49. return
  50. }
  51. type Symbol struct {
  52. Kind float64 `json:"kind,required"`
  53. Location SymbolLocation `json:"location,required"`
  54. Name string `json:"name,required"`
  55. JSON symbolJSON `json:"-"`
  56. }
  57. // symbolJSON contains the JSON metadata for the struct [Symbol]
  58. type symbolJSON struct {
  59. Kind apijson.Field
  60. Location apijson.Field
  61. Name apijson.Field
  62. raw string
  63. ExtraFields map[string]apijson.Field
  64. }
  65. func (r *Symbol) UnmarshalJSON(data []byte) (err error) {
  66. return apijson.UnmarshalRoot(data, r)
  67. }
  68. func (r symbolJSON) RawJSON() string {
  69. return r.raw
  70. }
  71. type SymbolLocation struct {
  72. Range SymbolLocationRange `json:"range,required"`
  73. Uri string `json:"uri,required"`
  74. JSON symbolLocationJSON `json:"-"`
  75. }
  76. // symbolLocationJSON contains the JSON metadata for the struct [SymbolLocation]
  77. type symbolLocationJSON struct {
  78. Range apijson.Field
  79. Uri apijson.Field
  80. raw string
  81. ExtraFields map[string]apijson.Field
  82. }
  83. func (r *SymbolLocation) UnmarshalJSON(data []byte) (err error) {
  84. return apijson.UnmarshalRoot(data, r)
  85. }
  86. func (r symbolLocationJSON) RawJSON() string {
  87. return r.raw
  88. }
  89. type SymbolLocationRange struct {
  90. End SymbolLocationRangeEnd `json:"end,required"`
  91. Start SymbolLocationRangeStart `json:"start,required"`
  92. JSON symbolLocationRangeJSON `json:"-"`
  93. }
  94. // symbolLocationRangeJSON contains the JSON metadata for the struct
  95. // [SymbolLocationRange]
  96. type symbolLocationRangeJSON struct {
  97. End apijson.Field
  98. Start apijson.Field
  99. raw string
  100. ExtraFields map[string]apijson.Field
  101. }
  102. func (r *SymbolLocationRange) UnmarshalJSON(data []byte) (err error) {
  103. return apijson.UnmarshalRoot(data, r)
  104. }
  105. func (r symbolLocationRangeJSON) RawJSON() string {
  106. return r.raw
  107. }
  108. type SymbolLocationRangeEnd struct {
  109. Character float64 `json:"character,required"`
  110. Line float64 `json:"line,required"`
  111. JSON symbolLocationRangeEndJSON `json:"-"`
  112. }
  113. // symbolLocationRangeEndJSON contains the JSON metadata for the struct
  114. // [SymbolLocationRangeEnd]
  115. type symbolLocationRangeEndJSON struct {
  116. Character apijson.Field
  117. Line apijson.Field
  118. raw string
  119. ExtraFields map[string]apijson.Field
  120. }
  121. func (r *SymbolLocationRangeEnd) UnmarshalJSON(data []byte) (err error) {
  122. return apijson.UnmarshalRoot(data, r)
  123. }
  124. func (r symbolLocationRangeEndJSON) RawJSON() string {
  125. return r.raw
  126. }
  127. type SymbolLocationRangeStart struct {
  128. Character float64 `json:"character,required"`
  129. Line float64 `json:"line,required"`
  130. JSON symbolLocationRangeStartJSON `json:"-"`
  131. }
  132. // symbolLocationRangeStartJSON contains the JSON metadata for the struct
  133. // [SymbolLocationRangeStart]
  134. type symbolLocationRangeStartJSON struct {
  135. Character apijson.Field
  136. Line apijson.Field
  137. raw string
  138. ExtraFields map[string]apijson.Field
  139. }
  140. func (r *SymbolLocationRangeStart) UnmarshalJSON(data []byte) (err error) {
  141. return apijson.UnmarshalRoot(data, r)
  142. }
  143. func (r symbolLocationRangeStartJSON) RawJSON() string {
  144. return r.raw
  145. }
  146. type FindTextResponse struct {
  147. AbsoluteOffset float64 `json:"absolute_offset,required"`
  148. LineNumber float64 `json:"line_number,required"`
  149. Lines FindTextResponseLines `json:"lines,required"`
  150. Path FindTextResponsePath `json:"path,required"`
  151. Submatches []FindTextResponseSubmatch `json:"submatches,required"`
  152. JSON findTextResponseJSON `json:"-"`
  153. }
  154. // findTextResponseJSON contains the JSON metadata for the struct
  155. // [FindTextResponse]
  156. type findTextResponseJSON struct {
  157. AbsoluteOffset apijson.Field
  158. LineNumber apijson.Field
  159. Lines apijson.Field
  160. Path apijson.Field
  161. Submatches apijson.Field
  162. raw string
  163. ExtraFields map[string]apijson.Field
  164. }
  165. func (r *FindTextResponse) UnmarshalJSON(data []byte) (err error) {
  166. return apijson.UnmarshalRoot(data, r)
  167. }
  168. func (r findTextResponseJSON) RawJSON() string {
  169. return r.raw
  170. }
  171. type FindTextResponseLines struct {
  172. Text string `json:"text,required"`
  173. JSON findTextResponseLinesJSON `json:"-"`
  174. }
  175. // findTextResponseLinesJSON contains the JSON metadata for the struct
  176. // [FindTextResponseLines]
  177. type findTextResponseLinesJSON struct {
  178. Text apijson.Field
  179. raw string
  180. ExtraFields map[string]apijson.Field
  181. }
  182. func (r *FindTextResponseLines) UnmarshalJSON(data []byte) (err error) {
  183. return apijson.UnmarshalRoot(data, r)
  184. }
  185. func (r findTextResponseLinesJSON) RawJSON() string {
  186. return r.raw
  187. }
  188. type FindTextResponsePath struct {
  189. Text string `json:"text,required"`
  190. JSON findTextResponsePathJSON `json:"-"`
  191. }
  192. // findTextResponsePathJSON contains the JSON metadata for the struct
  193. // [FindTextResponsePath]
  194. type findTextResponsePathJSON struct {
  195. Text apijson.Field
  196. raw string
  197. ExtraFields map[string]apijson.Field
  198. }
  199. func (r *FindTextResponsePath) UnmarshalJSON(data []byte) (err error) {
  200. return apijson.UnmarshalRoot(data, r)
  201. }
  202. func (r findTextResponsePathJSON) RawJSON() string {
  203. return r.raw
  204. }
  205. type FindTextResponseSubmatch struct {
  206. End float64 `json:"end,required"`
  207. Match FindTextResponseSubmatchesMatch `json:"match,required"`
  208. Start float64 `json:"start,required"`
  209. JSON findTextResponseSubmatchJSON `json:"-"`
  210. }
  211. // findTextResponseSubmatchJSON contains the JSON metadata for the struct
  212. // [FindTextResponseSubmatch]
  213. type findTextResponseSubmatchJSON struct {
  214. End apijson.Field
  215. Match apijson.Field
  216. Start apijson.Field
  217. raw string
  218. ExtraFields map[string]apijson.Field
  219. }
  220. func (r *FindTextResponseSubmatch) UnmarshalJSON(data []byte) (err error) {
  221. return apijson.UnmarshalRoot(data, r)
  222. }
  223. func (r findTextResponseSubmatchJSON) RawJSON() string {
  224. return r.raw
  225. }
  226. type FindTextResponseSubmatchesMatch struct {
  227. Text string `json:"text,required"`
  228. JSON findTextResponseSubmatchesMatchJSON `json:"-"`
  229. }
  230. // findTextResponseSubmatchesMatchJSON contains the JSON metadata for the struct
  231. // [FindTextResponseSubmatchesMatch]
  232. type findTextResponseSubmatchesMatchJSON struct {
  233. Text apijson.Field
  234. raw string
  235. ExtraFields map[string]apijson.Field
  236. }
  237. func (r *FindTextResponseSubmatchesMatch) UnmarshalJSON(data []byte) (err error) {
  238. return apijson.UnmarshalRoot(data, r)
  239. }
  240. func (r findTextResponseSubmatchesMatchJSON) RawJSON() string {
  241. return r.raw
  242. }
  243. type FindFilesParams struct {
  244. Query param.Field[string] `query:"query,required"`
  245. }
  246. // URLQuery serializes [FindFilesParams]'s query parameters as `url.Values`.
  247. func (r FindFilesParams) URLQuery() (v url.Values) {
  248. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  249. ArrayFormat: apiquery.ArrayQueryFormatComma,
  250. NestedFormat: apiquery.NestedQueryFormatBrackets,
  251. })
  252. }
  253. type FindSymbolsParams struct {
  254. Query param.Field[string] `query:"query,required"`
  255. }
  256. // URLQuery serializes [FindSymbolsParams]'s query parameters as `url.Values`.
  257. func (r FindSymbolsParams) URLQuery() (v url.Values) {
  258. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  259. ArrayFormat: apiquery.ArrayQueryFormatComma,
  260. NestedFormat: apiquery.NestedQueryFormatBrackets,
  261. })
  262. }
  263. type FindTextParams struct {
  264. Pattern param.Field[string] `query:"pattern,required"`
  265. }
  266. // URLQuery serializes [FindTextParams]'s query parameters as `url.Values`.
  267. func (r FindTextParams) URLQuery() (v url.Values) {
  268. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  269. ArrayFormat: apiquery.ArrayQueryFormatComma,
  270. NestedFormat: apiquery.NestedQueryFormatBrackets,
  271. })
  272. }