Skip to content

Commit

Permalink
feat: more types
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondill committed Aug 6, 2024
1 parent d0325a8 commit f899a3e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
1 change: 0 additions & 1 deletion rc.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- awesome_mode: api-level=9999:screen=on
local beautiful = require("beautiful")
local gfile = require("gears.filesystem")
-- Enable hotkeys help widget for VIM and other apps
-- when client with a matching name is opened:
Expand Down
43 changes: 30 additions & 13 deletions util/lgi/Gio/GFile.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---@meta
---@diagnostic disable: duplicate-doc-field This is used for overloading. Note: It's not perfect because the return types will not be narrowed.
---Note that none of the type definitions in this file are complete. If a field is missing, add it and report it.

---@alias GFileAttributeType "INVALID"| "STRING"| "BYTE_STRING"| "BOOLEAN"| "UINT32"| "INT32"| "UINT64"| "INT64"| "OBJECT"| "STRINGV"
Expand All @@ -14,19 +13,39 @@
---destination” before writing to it, although the implementation may not be
---exactly like that. This flag can only be used with g_file_replace() and its
---variants, including g_file_replace_contents(). Since 2.20
---@alias GFileCopyFlags "NONE" No flags set.
---|"OVERWRITE" Overwrite any existing file.
---|"BACKUP" Make a backup of any existing file.
---|"NOFOLLOW_SYMLINKS" Don’t follow symbolic links.
---|"ALL_METADATA" Copy all metadata information.
---|"NO_FALLBACK_FOR_MOVE" Don’t use copy and delete fallback if native move not supported
---|"TARGET_DEFAULT_PERMS" Use the default permissions for the target.
---|"TARGET_DEFAULT_MODIFIED_TIME" Use default modification timestamps instead of copying them from the source file. Since 2.80

---@alias GFileProgressCallback fun(current_num_bytes: integer, total_num_bytes: integer)

---@class GFileStatic
---@field new_for_path fun(path: string): GFile
---@field new_for_uri fun(uri: string): GFile
---@field new_tmp fun(tmpl?: string): GFile, GFileIOStream
---@field new_tmp fun(tmpl?: string): GError
---@field new_tmp fun(tmpl?: string): GFile?, GFileIOStream|GError
---@field new_tmp_async fun (tmpl?:string, io_priority: integer, cancellable?: GCancellable, callback: GAsyncReadyCallback<nil>)
---@field new_tmp_finish fun(task: GAsyncResult): GFile, GFileIOStream
---@field new_tmp_finish fun(task: GAsyncResult): GError
---@field new_tmp_finish fun(task: GAsyncResult): GFile?, GFileIOStream|GError

---@class GFile: userdata
---@field append_to fun(self: GFile, flags: Flags<GFileCreateFlags>, cancellable?: GCancellable): GFileOutputStream?, GError?
---@field append_to_async fun(self: GFile, flags: Flags<GFileCreateFlags>, io_priority: integer, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
---@field append_to_finish fun(self: GFile, result: GAsyncResult): GFileOutputStream?, GError?
---@field build_attribute_list_for_copy fun(self: GFile, flags: Flags<GFileCopyFlags>, cancellable?: GCancellable): string?, GError?
---@field copy fun(self: GFile, destination: GFile, flags: Flags<GFileCopyFlags>, cancellable?: GCancellable, progress_callback?: GFileProgressCallback): boolean, GError?
---@field copy_async fun(self: GFile, destination: GFile, flags: Flags<GFileCopyFlags>, io_priority: integer, cancellable?: GCancellable, progress_callback?: GFileProgressCallback, callback: GAsyncReadyCallback<GFile>)
---@field copy_finish fun(self: GFile, result: GAsyncResult): boolean, GError?
---@field copy_attributes fun(self: GFile, destination: GFile, flags: Flags<GFileCopyFlags>, cancellable?: GCancellable): boolean, GError?
---@field create fun(self: GFile, flags: Flags<GFileCreateFlags>, cancellable?: GCancellable): GFileOutputStream?, GError?
---@field create_async fun(self: GFile, flags: Flags<GFileCreateFlags>, io_priority: integer, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
---@field create_finish fun(self: GFile, result: GAsyncResult): GFileOutputStream?, GError?
---@field equal fun(self: GFile, other: GFile): boolean
---@field get_relative_path fun(self: GFile, other: GFile): string?
---@field get_uri fun(self: GFile): string
---@field query_exists fun(self: GFile, cancellable?: GCancellable): boolean
---Returns G_FILE_TYPE_UNKNOWN if the file does not exist.
---@field query_file_type fun(self: GFile, flags: Flags<GFileQueryInfoFlags>, cancellable?: GCancellable): GFileType
Expand All @@ -35,10 +54,8 @@
---@field get_path fun(self: GFile): string?
---@field get_basename fun(self: GFile): string?
---@field load_contents_async fun(self: GFile, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
---@field load_contents_finish fun(self: GFile, task: GAsyncResult): nil, GError
---@field load_contents_finish fun(self: GFile, task: GAsyncResult): contents: string, length: number, etag: string
---@field load_contents fun(self: GFile, cancellable?: GCancellable): contents: string, length: number, etag: string
---@field load_contents fun(self: GFile, cancellable?: GCancellable): nil, GError
---@field load_contents_finish fun(self: GFile, task: GAsyncResult): contents: string|false, etag: string|GError
---@field load_contents fun(self: GFile, cancellable?: GCancellable): contents: string|false, etag: string|GError
---@field query_info_async fun(self: GFile, attributes: string, flags: Flags<GFileQueryInfoFlags>, io_priority: integer, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
---@field query_info_finish fun(self: GFile, task: GAsyncResult): GFileInfo?, GError?
---@field enumerate_children_async fun(self: GFile, attributes: string, flags: Flags<GFileQueryInfoFlags>, io_priority: integer, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
Expand All @@ -52,11 +69,11 @@
---@field replace_contents_bytes_async fun(self: GFile, contents: GBytes, etag?: string, make_backup: boolean, flags: Flags<GFileCreateFlags>, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
---WARNING: This function *does not* copy the contents of `contents` and so it must not be freed. Use replace_contents_bytes_async() instead.
---@field replace_contents_async fun(self: GFile, contents: string, etag?: string, make_backup: boolean, flags: Flags<GFileCreateFlags>, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
---@field replace_contents_finish fun(self: GFile, task: GAsyncResult): true, new_etag: string?
---@field replace_contents_finish fun(self: GFile, task: GAsyncResult): false, GError
---@field replace_contents fun(self: GFile, contents: string, etag?: string, make_backup: boolean, flags: Flags<GFileCreateFlags>, cancellable?: GCancellable): true, new_etag: string?
---@field replace_contents fun(self: GFile, contents: string, etag?: string, make_backup: boolean, flags: Flags<GFileCreateFlags>, cancellable?: GCancellable): false, GError
---@field replace_contents_finish fun(self: GFile, task: GAsyncResult): new_etag: string|false, GError?
---@field replace_contents fun(self: GFile, contents: string, etag?: string, make_backup: boolean, flags: Flags<GFileCreateFlags>, cancellable?: GCancellable): new_etag: string|false, GError?
---@field delete fun(self: GFile, cancellable?: GCancellable): boolean, GError?
---@field delete_async fun(self: GFile, io_priority: integer, cancellable?: GCancellable, callback: GAsyncReadyCallback<GFile>)
---@field delete_finish fun(self: GFile, result: GAsyncResult): boolean, GError?

---@class GFileIOStream TODO:

Expand Down
2 changes: 2 additions & 0 deletions util/lgi/Gio/GFileInfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
---Gets the file’s size (in bytes)
---It is an error to call this if the GFileInfo does not contain G_FILE_ATTRIBUTE_STANDARD_SIZE.
---@field get_size fun(self: GFileInfo): number
---It is an error to call this if the GFileInfo does not contain G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
---@field get_display_name fun(self: GFileInfo): string
---@field get_attribute_string fun(self: GFileInfo, attribute: string): string?
---@field get_attribute_type fun(self: GFileInfo, attribute: string): GFileAttributeType
---@field get_attribute_object fun(self: GFileInfo, attribute: string): table?
Expand Down
2 changes: 2 additions & 0 deletions util/lgi/Gio/GOutputStream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
---@field splice fun(self: GOutputStream, source: GInputStream, flags: Flags<GOutputStreamSpliceFlags>, cancellable?: GCancellable): size: integer, GError?
---@field splice_async fun(self: GOutputStream, source: GInputStream, flags: Flags<GOutputStreamSpliceFlags>, io_priority: integer, cancellable?: GCancellable, callback?: GAsyncReadyCallback<GOutputStream>)
---@field splice_finish fun(self: GOutputStream, task: userdata): size: integer?, GError?

---@class GFileOutputStream: GOutputStream
4 changes: 4 additions & 0 deletions util/lgi/Gio/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
---@class Gio
---@field FILE_ATTRIBUTE_STANDARD_TYPE "standard::type"
---@field FILE_ATTRIBUTE_STANDARD_NAME "standard::name"
---@field FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "standard::display-name"
---@field FILE_ATTRIBUTE_STANDARD_SIZE "standard::size"
---@field File GFileStatic
---@field DataInputStream GDataInputStreamStatic
---@field FileInfo GFileInfoStatic
---@field FileQueryInfoFlags FlagsDefinition<GFileQueryInfoFlags>
---@field FileCreateFlags FlagsDefinition<GFileCreateFlags>
---@field FileCopyFlags FlagsDefinition<GFileCopyFlags>
---@field FileType EnumDefinition<GFileType>
---@field IOErrorEnum EnumDefinition<string>
---@field Subprocess GSubprocessStatic
Expand Down

0 comments on commit f899a3e

Please sign in to comment.