question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocompletion for commit SHA

See original GitHub issue

When I work on code review comments, I often refer to a commit where this particular issue was solved. This requires manually copy & pasting the commit sha and this really annoys me.

Wouldn’t it be cool, if you could trigger an autocomplete prompt for commit sha like you can do for GitHub users with the @-Sign?

image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
artusmcommented, Aug 20, 2020

@fregante

Help wanted to reverse engineer the existing @ or # autocompletion

An example of a custom autocompletion.


async function apiRequest(text) {
  const values = ["value", "value1", "value2", "test1", "value2"];

  return values.filter((value) =>
    value.toLowerCase().includes(text.toLowerCase())
  );
}

async function searchSHA(text) {
  const autocompleteValues = await apiRequest(text);

  const fragment = document.createElement("ul");
  fragment.setAttribute("role", "listbox");
  fragment.className =
    "suggester-container suggester suggestions list-style-none position-absolute";

  fragment.innerHTML = autocompleteValues
    .map(
      (
        value,
        i
      ) => `<li role="option" id="suggester-example-${i}" data-value="${value}">
    <span>${value}</span>
    <small>${value}</small>
  </li>`
    )
    .join("");

  return {
    matched: autocompleteValues.length > 0,
    fragment,
  };
}

const textExpander = document.querySelector("text-expander");
textExpander.setAttribute("keys", `${textExpander.getAttribute("keys")} !`);
textExpander.addEventListener("text-expander-change", (event) => {
  const { key, provide, text } = event.detail;
  if (key !== "!") return;

  provide(searchSHA(text));
});
textExpander.addEventListener("text-expander-value", (e) => {
  if ("!" !== e.detail.key) return;

  e.detail.value = `--__${e.detail.item.dataset.value}__--`;
});

Peek 2020-08-20 03-18

3reactions
fregantecommented, Sep 4, 2020

That looks correct according to https://github.com/github/text-expander-element 🎉

I suppose your code is only missing the api.v4 call to get the commit list. Also it can use JSX to generate the fragment effortlessly

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autocompletion for commit SHA · Issue #1547 - GitHub
When I work on code review comments, I often refer to a commit where this particular issue was solved. This requires manually copy...
Read more >
git: hash autocomplete - Stack Overflow
You can refer to a commit by only its first few characters: git will autocomplete internally: git checkout 9771. Thus, you actually don't...
Read more >
git - when checkout a previous commit, Is there a quick way to ...
The short SHA1 are mentioned in "Git Tools - Revision Selection", but git rev-parse section on "SPECIFYING REVISIONS" mentions also (small ...
Read more >
Issuehunt
Autocompletion for commit SHA #1547 ... When I work on code review comments, I often refer to a commit where this particular issue...
Read more >
How did I get the git commits to show up in autocomplete?
I wanted to know what is giving me the ability to see commits on my mac using tab completion so that I can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found