find.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 *[]Match, 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 Match struct {
  52. AbsoluteOffset float64 `json:"absolute_offset,required"`
  53. LineNumber float64 `json:"line_number,required"`
  54. Lines MatchLines `json:"lines,required"`
  55. Path MatchPath `json:"path,required"`
  56. Submatches []MatchSubmatch `json:"submatches,required"`
  57. JSON matchJSON `json:"-"`
  58. }
  59. // matchJSON contains the JSON metadata for the struct [Match]
  60. type matchJSON struct {
  61. AbsoluteOffset apijson.Field
  62. LineNumber apijson.Field
  63. Lines apijson.Field
  64. Path apijson.Field
  65. Submatches apijson.Field
  66. raw string
  67. ExtraFields map[string]apijson.Field
  68. }
  69. func (r *Match) UnmarshalJSON(data []byte) (err error) {
  70. return apijson.UnmarshalRoot(data, r)
  71. }
  72. func (r matchJSON) RawJSON() string {
  73. return r.raw
  74. }
  75. type MatchLines struct {
  76. Text string `json:"text,required"`
  77. JSON matchLinesJSON `json:"-"`
  78. }
  79. // matchLinesJSON contains the JSON metadata for the struct [MatchLines]
  80. type matchLinesJSON struct {
  81. Text apijson.Field
  82. raw string
  83. ExtraFields map[string]apijson.Field
  84. }
  85. func (r *MatchLines) UnmarshalJSON(data []byte) (err error) {
  86. return apijson.UnmarshalRoot(data, r)
  87. }
  88. func (r matchLinesJSON) RawJSON() string {
  89. return r.raw
  90. }
  91. type MatchPath struct {
  92. Text string `json:"text,required"`
  93. JSON matchPathJSON `json:"-"`
  94. }
  95. // matchPathJSON contains the JSON metadata for the struct [MatchPath]
  96. type matchPathJSON struct {
  97. Text apijson.Field
  98. raw string
  99. ExtraFields map[string]apijson.Field
  100. }
  101. func (r *MatchPath) UnmarshalJSON(data []byte) (err error) {
  102. return apijson.UnmarshalRoot(data, r)
  103. }
  104. func (r matchPathJSON) RawJSON() string {
  105. return r.raw
  106. }
  107. type MatchSubmatch struct {
  108. End float64 `json:"end,required"`
  109. Match MatchSubmatchesMatch `json:"match,required"`
  110. Start float64 `json:"start,required"`
  111. JSON matchSubmatchJSON `json:"-"`
  112. }
  113. // matchSubmatchJSON contains the JSON metadata for the struct [MatchSubmatch]
  114. type matchSubmatchJSON struct {
  115. End apijson.Field
  116. Match apijson.Field
  117. Start apijson.Field
  118. raw string
  119. ExtraFields map[string]apijson.Field
  120. }
  121. func (r *MatchSubmatch) UnmarshalJSON(data []byte) (err error) {
  122. return apijson.UnmarshalRoot(data, r)
  123. }
  124. func (r matchSubmatchJSON) RawJSON() string {
  125. return r.raw
  126. }
  127. type MatchSubmatchesMatch struct {
  128. Text string `json:"text,required"`
  129. JSON matchSubmatchesMatchJSON `json:"-"`
  130. }
  131. // matchSubmatchesMatchJSON contains the JSON metadata for the struct
  132. // [MatchSubmatchesMatch]
  133. type matchSubmatchesMatchJSON struct {
  134. Text apijson.Field
  135. raw string
  136. ExtraFields map[string]apijson.Field
  137. }
  138. func (r *MatchSubmatchesMatch) UnmarshalJSON(data []byte) (err error) {
  139. return apijson.UnmarshalRoot(data, r)
  140. }
  141. func (r matchSubmatchesMatchJSON) RawJSON() string {
  142. return r.raw
  143. }
  144. type Symbol struct {
  145. Kind float64 `json:"kind,required"`
  146. Location SymbolLocation `json:"location,required"`
  147. Name string `json:"name,required"`
  148. JSON symbolJSON `json:"-"`
  149. }
  150. // symbolJSON contains the JSON metadata for the struct [Symbol]
  151. type symbolJSON struct {
  152. Kind apijson.Field
  153. Location apijson.Field
  154. Name apijson.Field
  155. raw string
  156. ExtraFields map[string]apijson.Field
  157. }
  158. func (r *Symbol) UnmarshalJSON(data []byte) (err error) {
  159. return apijson.UnmarshalRoot(data, r)
  160. }
  161. func (r symbolJSON) RawJSON() string {
  162. return r.raw
  163. }
  164. type SymbolLocation struct {
  165. Range SymbolLocationRange `json:"range,required"`
  166. Uri string `json:"uri,required"`
  167. JSON symbolLocationJSON `json:"-"`
  168. }
  169. // symbolLocationJSON contains the JSON metadata for the struct [SymbolLocation]
  170. type symbolLocationJSON struct {
  171. Range apijson.Field
  172. Uri apijson.Field
  173. raw string
  174. ExtraFields map[string]apijson.Field
  175. }
  176. func (r *SymbolLocation) UnmarshalJSON(data []byte) (err error) {
  177. return apijson.UnmarshalRoot(data, r)
  178. }
  179. func (r symbolLocationJSON) RawJSON() string {
  180. return r.raw
  181. }
  182. type SymbolLocationRange struct {
  183. End SymbolLocationRangeEnd `json:"end,required"`
  184. Start SymbolLocationRangeStart `json:"start,required"`
  185. JSON symbolLocationRangeJSON `json:"-"`
  186. }
  187. // symbolLocationRangeJSON contains the JSON metadata for the struct
  188. // [SymbolLocationRange]
  189. type symbolLocationRangeJSON struct {
  190. End apijson.Field
  191. Start apijson.Field
  192. raw string
  193. ExtraFields map[string]apijson.Field
  194. }
  195. func (r *SymbolLocationRange) UnmarshalJSON(data []byte) (err error) {
  196. return apijson.UnmarshalRoot(data, r)
  197. }
  198. func (r symbolLocationRangeJSON) RawJSON() string {
  199. return r.raw
  200. }
  201. type SymbolLocationRangeEnd struct {
  202. Character float64 `json:"character,required"`
  203. Line float64 `json:"line,required"`
  204. JSON symbolLocationRangeEndJSON `json:"-"`
  205. }
  206. // symbolLocationRangeEndJSON contains the JSON metadata for the struct
  207. // [SymbolLocationRangeEnd]
  208. type symbolLocationRangeEndJSON struct {
  209. Character apijson.Field
  210. Line apijson.Field
  211. raw string
  212. ExtraFields map[string]apijson.Field
  213. }
  214. func (r *SymbolLocationRangeEnd) UnmarshalJSON(data []byte) (err error) {
  215. return apijson.UnmarshalRoot(data, r)
  216. }
  217. func (r symbolLocationRangeEndJSON) RawJSON() string {
  218. return r.raw
  219. }
  220. type SymbolLocationRangeStart struct {
  221. Character float64 `json:"character,required"`
  222. Line float64 `json:"line,required"`
  223. JSON symbolLocationRangeStartJSON `json:"-"`
  224. }
  225. // symbolLocationRangeStartJSON contains the JSON metadata for the struct
  226. // [SymbolLocationRangeStart]
  227. type symbolLocationRangeStartJSON struct {
  228. Character apijson.Field
  229. Line apijson.Field
  230. raw string
  231. ExtraFields map[string]apijson.Field
  232. }
  233. func (r *SymbolLocationRangeStart) UnmarshalJSON(data []byte) (err error) {
  234. return apijson.UnmarshalRoot(data, r)
  235. }
  236. func (r symbolLocationRangeStartJSON) RawJSON() string {
  237. return r.raw
  238. }
  239. type FindFilesParams struct {
  240. Query param.Field[string] `query:"query,required"`
  241. }
  242. // URLQuery serializes [FindFilesParams]'s query parameters as `url.Values`.
  243. func (r FindFilesParams) URLQuery() (v url.Values) {
  244. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  245. ArrayFormat: apiquery.ArrayQueryFormatComma,
  246. NestedFormat: apiquery.NestedQueryFormatBrackets,
  247. })
  248. }
  249. type FindSymbolsParams struct {
  250. Query param.Field[string] `query:"query,required"`
  251. }
  252. // URLQuery serializes [FindSymbolsParams]'s query parameters as `url.Values`.
  253. func (r FindSymbolsParams) URLQuery() (v url.Values) {
  254. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  255. ArrayFormat: apiquery.ArrayQueryFormatComma,
  256. NestedFormat: apiquery.NestedQueryFormatBrackets,
  257. })
  258. }
  259. type FindTextParams struct {
  260. Pattern param.Field[string] `query:"pattern,required"`
  261. }
  262. // URLQuery serializes [FindTextParams]'s query parameters as `url.Values`.
  263. func (r FindTextParams) URLQuery() (v url.Values) {
  264. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  265. ArrayFormat: apiquery.ArrayQueryFormatComma,
  266. NestedFormat: apiquery.NestedQueryFormatBrackets,
  267. })
  268. }