Skip to content

Commit

Permalink
Merge pull request ceedubs#14 from fedragon/allow-relative-filenames
Browse files Browse the repository at this point in the history
Use relative paths if `--tag-relative=yes`
  • Loading branch information
ceedubs committed Nov 2, 2015
2 parents e643cca + a507a19 commit b817466
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ CtagsKeys.ctagsParams ~= (default => default.copy(tagFileName = "TAGS", extraArg

If you just want to use this plugin to unzip dependency sources so you can generate ctags outside of SBT, you could set `net.ceedubs.sbtctags.CtagsKeys.ctagsGeneration := { _ => () }` to make the generation of ctags a noop.

## Relative paths

If you need/want to have relative paths in your `.tags` file, set the following to your sbt-ctags file:

```scala
CtagsKeys.ctagsParams ~= (_.copy(
useRelativePaths = true))
```

# Disclaimers and warnings #
Be very careful if you are going to change the `dependencySrcUnzipDir` setting. This directory is cleared every time the `gen-ctags` task runs.

Expand Down
22 changes: 18 additions & 4 deletions src/main/scala/net/ceedubs/sbtctags/SbtCtags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final case class CtagsParams(
excludes: Seq[String],
languages: Seq[String],
tagFileName: String,
useRelativePaths: Boolean,
extraArgs: Seq[String])

object CtagsKeys {
Expand All @@ -40,7 +41,7 @@ object SbtCtags extends Plugin {
Seq(srcDir, testDir, javaSrcDir, javaTestDir, depSrcDir)
},

CtagsKeys.ctagsGeneration in ThisBuild := defaultCtagsGeneration,
CtagsKeys.ctagsGeneration in ThisBuild := defaultCtagsGeneration(Keys.baseDirectory.value) _,

CtagsKeys.genCtags <<= (Keys.state, CtagsKeys.dependencySrcUnzipDir, CtagsKeys.ctagsParams, CtagsKeys.ctagsSrcFileFilter, CtagsKeys.ctagsGeneration, CtagsKeys.ctagsSrcDirs, Keys.streams) map genCtags
)
Expand All @@ -50,14 +51,27 @@ object SbtCtags extends Plugin {
excludes = Seq("log"),
languages = Seq("scala", "java"),
tagFileName = ".tags",
useRelativePaths = false,
extraArgs = Seq.empty)

def defaultCtagsGeneration(context: CtagsGenerationContext) {
def defaultCtagsGeneration(base: File)(context: CtagsGenerationContext) {
val ctagsParams = context.ctagsParams
val dirArgs = context.srcDirs.map(_.getAbsolutePath).mkString(" ")

val toPath: File => String = file =>
if(ctagsParams.useRelativePaths)
file.relativeTo(base).fold(file.getAbsolutePath)(_.getPath)
else file.getAbsolutePath

val dirArgs = context.srcDirs.map(toPath).mkString(" ")
val excludeArgs = ctagsParams.excludes.map(x => s"--exclude=$x").mkString(" ")
val languagesArgs = if (ctagsParams.languages.isEmpty) "" else s"--languages=${ctagsParams.languages.mkString(",")}"
val extraArgs = ctagsParams.extraArgs.mkString(" ")
val extraArgs = {
val args =
if(ctagsParams.useRelativePaths)
"--tag-relative=yes" +: ctagsParams.extraArgs
else ctagsParams.extraArgs
args.mkString(" ")
}
// will look something like "ctags --exclude=.git --exclude=log --languages=scala -f .tags -R src/main/scala target/sbt-ctags-dep-srcs"
val ctagsCmd = s"${ctagsParams.executable} $excludeArgs $languagesArgs -f ${ctagsParams.tagFileName} $extraArgs -R $dirArgs"
context.log.info(s"running this command to generate ctags: $ctagsCmd")
Expand Down

0 comments on commit b817466

Please sign in to comment.