{"id":17543296,"url":"https://github.com/fatih/motion","last_synced_at":"2025-04-07T13:08:41.823Z","repository":{"id":43788460,"uuid":"51225120","full_name":"fatih/motion","owner":"fatih","description":"Navigation and insight in Go","archived":false,"fork":false,"pushed_at":"2023-02-16T09:25:41.000Z","size":55,"stargazers_count":184,"open_issues_count":3,"forks_count":18,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-31T11:08:17.707Z","etag":null,"topics":["go","golang","navigation","tool"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fatih.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-06T22:25:30.000Z","updated_at":"2025-02-28T03:02:08.000Z","dependencies_parsed_at":"2024-06-18T14:02:39.090Z","dependency_job_id":null,"html_url":"https://github.com/fatih/motion","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fmotion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fmotion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fmotion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fmotion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fatih","download_url":"https://codeload.github.com/fatih/motion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","navigation","tool"],"created_at":"2024-10-21T00:23:39.236Z","updated_at":"2025-04-07T13:08:41.807Z","avatar_url":"https://github.com/fatih.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Motion [![](https://github.com/fatih/motion/workflows/build/badge.svg)](https://github.com/fatih/motion/actions)\n\nMotion is a tool that was designed to work with editors. It is providing\ncontextual information for a given offset(option) from a file or directory of\nfiles.  Editors can use these informations to implement navigation, text\nediting, etc... that are specific to a Go source code.\n\nIt's optimized and created to work with\n[vim-go](https://github.com/fatih/vim-go), but it's designed to work with any\neditor.  It's currently work in progress and open to change.\n\n# Install\n\n```bash\ngo get github.com/fatih/motion\n```\n\n# Usage\n\n`motion` is meant to be run via the editor. Currently it has the following\nmodes you can use:\n\n* `decls`: returns a list of declarations based on the `-include` flag\n* `enclosing`: returns information about the enclosing function for a given\n  offset\n* `next`: returns the next function information for a given offset\n* `prev`: returns the previous function information for a given offset\n* `comment`: returns information about the a comment block (if any).\n\nA `function information` is currently the following type definition (defined as\n`astcontext.Func`):\n\n```\ntype Func struct {\n\t// Signature of the function\n\tSignature *FuncSignature `json:\"sig\" vim:\"sig\"`\n\n\t// position of the \"func\" keyword\n\tFuncPos *Position `json:\"func\" vim:\"func\"`\n\tLbrace  *Position `json:\"lbrace\" vim:\"lbrace\"` // position of \"{\"\n\tRbrace  *Position `json:\"rbrace\" vim:\"rbrace\"` // position of \"}\"\n\n\t// position of the doc comment, only for *ast.FuncDecl\n\tDoc *Position `json:\"doc,omitempty\" vim:\"doc,omitempty\"`\n\n\tnode ast.Node // either *ast.FuncDecl or *ast.FuncLit\n}\n```\n\n`motion` can output the information currently in formats: `json` and `vim`.\n\nAn example execution for the `enclosing` mode and output in `json` format is:\n\n```\n$ motion -file testdata/main.go -offset 180 -mode enclosing --format json\n{\n\t\"mode\": \"enclosing\",\n\t\"func\": {\n\t\t\"sig\": {\n\t\t\t\"full\": \"func Bar() (string, error)\",\n\t\t\t\"recv\": \"\",\n\t\t\t\"name\": \"Bar\",\n\t\t\t\"in\": \"\",\n\t\t\t\"out\": \"string, error\"\n\t\t},\n\t\t\"func\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 174,\n\t\t\t\"line\": 15,\n\t\t\t\"col\": 1\n\t\t},\n\t\t\"lbrace\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 201,\n\t\t\t\"line\": 15,\n\t\t\t\"col\": 28\n\t\t},\n\t\t\"rbrace\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 225,\n\t\t\t\"line\": 17,\n\t\t\t\"col\": 1\n\t\t}\n\t}\n}\n```\n\nTo include the doc comments for function declarations include the\n`--parse-comments` flag:\n\n```\n$ motion -file testdata/main.go -offset 180 -mode enclosing --format json --parse-comments\n{\n\t\"mode\": \"enclosing\",\n\t\"func\": {\n\t\t\"sig\": {\n\t\t\t\"full\": \"func Bar() (string, error)\",\n\t\t\t\"recv\": \"\",\n\t\t\t\"name\": \"Bar\",\n\t\t\t\"in\": \"\",\n\t\t\t\"out\": \"string, error\"\n\t\t},\n\t\t\"func\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 174,\n\t\t\t\"line\": 15,\n\t\t\t\"col\": 1\n\t\t},\n\t\t\"lbrace\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 201,\n\t\t\t\"line\": 15,\n\t\t\t\"col\": 28\n\t\t},\n\t\t\"rbrace\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 225,\n\t\t\t\"line\": 17,\n\t\t\t\"col\": 1\n\t\t},\n\t\t\"doc\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 134,\n\t\t\t\"line\": 14,\n\t\t\t\"col\": 1\n\t\t}\n\t}\n}\n```\n\nFor example the same query, but with mode `-mode next` returns a different\nresult. Instead it returns the next function inside the source code:\n\n```\n$ motion -file testdata/main.go -offset 180 -mode next --format json\n{\n\t\"mode\": \"next\",\n\t\"func\": {\n\t\t\"sig\": {\n\t\t\t\"full\": \"func example() error\",\n\t\t\t\"recv\": \"\",\n\t\t\t\"name\": \"example\",\n\t\t\t\"in\": \"\",\n\t\t\t\"out\": \"error\"\n\t\t},\n\t\t\"func\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 318,\n\t\t\t\"line\": 21,\n\t\t\t\"col\": 1\n\t\t},\n\t\t\"lbrace\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 339,\n\t\t\t\"line\": 21,\n\t\t\t\"col\": 22\n\t\t},\n\t\t\"rbrace\": {\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"offset\": 402,\n\t\t\t\"line\": 29,\n\t\t\t\"col\": 1\n\t\t}\n\t}\n}\n```\n\nIf there are not functions available for any mode, it returns an error in the\nspecified format:\n\n```\n$ motion -file testdata/main.go -offset 330 -mode next --format json\n{\n\t\"err\": \"no functions found\"\n}\n```\n\nFor the mode `decls`, we pass the file (you can also pass a directory)\nand instruct to only include function declarations with the `-include func`\nflag:\n```\n$ motion -file testdata/main.go -mode decls -include func\n{\n\t\"mode\": \"decls\",\n\t\"decls\": [\n\t\t{\n\t\t\t\"keyword\": \"func\",\n\t\t\t\"ident\": \"main\",\n\t\t\t\"full\": \"func main()\",\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"line\": 9,\n\t\t\t\"col\": 1\n\t\t},\n\t\t{\n\t\t\t\"keyword\": \"func\",\n\t\t\t\"ident\": \"Bar\",\n\t\t\t\"full\": \"func Bar() (string, error)\",\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"line\": 15,\n\t\t\t\"col\": 1\n\t\t},\n\t\t{\n\t\t\t\"keyword\": \"func\",\n\t\t\t\"ident\": \"example\",\n\t\t\t\"full\": \"func example() error\",\n\t\t\t\"filename\": \"testdata/main.go\",\n\t\t\t\"line\": 21,\n\t\t\t\"col\": 1\n\t\t}\n\t]\n}\n```\n\nIn the `comment` mode it will try to get information about the comment block for\na given offset:\n```\n$ motion -mode comment -file ./vim/vim.go -offset 3\n{\n        \"mode\": \"comment\",\n        \"comment\": {\n                \"startLine\": 1,\n                \"startCol\": 1,\n                \"endLine\": 3,\n                \"endCol\": 50\n        }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fmotion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffatih%2Fmotion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fmotion/lists"}