find.go 9.7 KB

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