-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GSoC 2024- Scaladoc Search in Protosearch #241
Open
golden-skipper03
wants to merge
26
commits into
cozydev-pink:main
Choose a base branch
from
golden-skipper03:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
79382bb
integration
golden-skipper03 6b7e322
improved-integration
golden-skipper03 b386ff3
implement-changes
golden-skipper03 db3e994
create-scaladoc-ubmodule
golden-skipper03 5cd8f5b
error-fixing
golden-skipper03 bb708e6
revert-unneeded-changes
golden-skipper03 df92d97
handle-warnings-and-update
golden-skipper03 74b6812
format-code
golden-skipper03 903435d
scala-version-build-settings
golden-skipper03 f3e1f84
git-flow
golden-skipper03 4a1a917
add-parser-tests
golden-skipper03 1e88a7f
git-workglow
golden-skipper03 07668f4
add-header
golden-skipper03 c406669
Tweak scaladoc project build
valencik b608833
Remove scaladoc project from rootJVM
valencik 45f2f8f
Merge pull request #1 from valencik/abhi-build
golden-skipper03 844da27
Add initial plugin to get all source files
valencik 8ca6f6d
Build and write Index to static location
valencik a797fdf
Fix plugin project dependsOn (scaladoc not cross)
valencik 49f513e
Rename to `createScaladocIndex`, parameterize
valencik 69e856f
Merge branch 'main' of upstream
golden-skipper03 4a7e3ab
Add `index` query param support to search.js
valencik 0af21a1
Add support for `type=scaladoc` query param
valencik 1d417e6
Fix reading big files in ProtosearchScaladocPlugin
valencik 47dee14
Merge pull request #2 from valencik/index-param
golden-skipper03 a45c31f
improve-search-ui
golden-skipper03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 62 additions & 2 deletions
64
laikaIO/src/main/resources/pink/cozydev/protosearch/sbt/search.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 6 additions & 32 deletions
38
laikaIO/src/main/resources/pink/cozydev/protosearch/sbt/worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
sbt/src/main/scala/pink/cozydev/protosearch/ProtosearchScaladocPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2022 CozyDev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pink.cozydev.protosearch.sbt | ||
|
||
import sbt.* | ||
import sbt.Keys.* | ||
import sbt.nio.file.FileTreeView | ||
import fs2.{Stream, Chunk} | ||
import fs2.io.file.{Files, Path} | ||
import cats.effect.IO | ||
import cats.effect.unsafe.implicits.global | ||
import cats.syntax.all._ | ||
import java.nio.file.{Path => JPath} | ||
|
||
import pink.cozydev.protosearch.scaladoc.{ParseScaladoc, ScaladocIndexer} | ||
import pink.cozydev.protosearch.MultiIndex | ||
|
||
object ProtosearchScaladocPlugin extends AutoPlugin { | ||
|
||
lazy val createScaladocIndex: TaskKey[File] = | ||
taskKey[File]("Create a Search Index based on Scaladocs within the project") | ||
|
||
private def buildScaladocIndex: Def.Initialize[Task[File]] = Def.task { | ||
val logger = streams.value.log | ||
val sourceGlobs = (Compile / sourceDirectories).value.map(f => f.toGlob / "**" / "*.scala") | ||
val scalaSourceFiles: Seq[JPath] = sourceGlobs.flatMap(g => | ||
FileTreeView.default.list(g).collect { | ||
case (path, attributes) if attributes.isRegularFile => path | ||
} | ||
) | ||
|
||
val scaladocInfos = Stream | ||
.emits(scalaSourceFiles) | ||
.flatMap { path => | ||
val p = Path.fromNioPath(path) | ||
val getContent = Files[IO].readAll(p).through(fs2.text.utf8.decode).compile.string | ||
Stream.eval(getContent).map(ParseScaladoc.parseAndExtractInfo) | ||
} | ||
.flatMap(Stream.emits) | ||
|
||
val buildIndex = scaladocInfos.compile.toList.map(ScaladocIndexer.createScaladocIndex) | ||
|
||
val projName = name.value | ||
val targetDir = target.value | ||
val outputFile = targetDir / s"$projName.idx" | ||
val writer = Files[IO].writeAll(Path.fromNioPath(outputFile.toPath())) | ||
val writeIndex = buildIndex.flatMap { index => | ||
val numDocs = index.indexes.head._2.numDocs | ||
val log = IO(logger.info(s"Created index with ${numDocs} docs at $outputFile")) | ||
val indexBytes = MultiIndex.codec | ||
.encode(index) | ||
.map(_.bytes) | ||
.toEither | ||
.leftMap(err => new Throwable(err.message)) | ||
val bytes: Stream[IO, Byte] = | ||
Stream.fromEither[IO](indexBytes).flatMap(bv => Stream.chunk(Chunk.byteVector(bv))) | ||
log *> bytes.through(writer).compile.drain | ||
} | ||
|
||
writeIndex.unsafeRunSync() | ||
outputFile | ||
} | ||
override val trigger = allRequirements | ||
|
||
override def requires = plugins.JvmPlugin | ||
|
||
override lazy val projectSettings: Seq[Setting[_]] = Seq( | ||
createScaladocIndex := buildScaladocIndex.value | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only needed this during testing.