Skip to content
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

Remove unused internal or unexported functions #3481

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions internal/action/infocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ headerLoop:
return chosen, suggestions
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

// OptionComplete autocompletes options
func OptionComplete(b *buffer.Buffer) ([]string, []string) {
c := b.GetActiveCursor()
Expand Down
5 changes: 0 additions & 5 deletions internal/buffer/line_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,6 @@ func (la *LineArray) deleteLines(y1, y2 int) {
la.lines = la.lines[:y1+copy(la.lines[y1:], la.lines[y2+1:])]
}

// DeleteByte deletes the byte at a position
func (la *LineArray) deleteByte(pos Loc) {
la.lines[pos.Y].data = la.lines[pos.Y].data[:pos.X+copy(la.lines[pos.Y].data[pos.X:], la.lines[pos.Y].data[pos.X+1:])]
}

// Substr returns the string representation between two locations
func (la *LineArray) Substr(start, end Loc) []byte {
startX := runeToByteIndex(start.X, la.lines[start.Y].data)
Expand Down
12 changes: 0 additions & 12 deletions internal/config/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,3 @@ func FindPlugin(name string) *Plugin {
}
return pl
}

// FindAnyPlugin does not require the plugin to be enabled
func FindAnyPlugin(name string) *Plugin {
var pl *Plugin
for _, p := range Plugins {
if p.Name == name {
pl = p
break
}
}
return pl
}
4 changes: 0 additions & 4 deletions internal/config/rtfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ func (af assetFile) Data() ([]byte, error) {
return rt.Asset(string(af))
}

func (nf namedFile) Name() string {
alexandear marked this conversation as resolved.
Show resolved Hide resolved
return nf.name
}

// AddRuntimeFile registers a file for the given filetype
func AddRuntimeFile(fileType RTFiletype, file RuntimeFile) {
allFiles[fileType] = append(allFiles[fileType], file)
Expand Down
12 changes: 0 additions & 12 deletions internal/util/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package util

import (
"fmt"
"log"
"runtime"
"time"

humanize "github.com/dustin/go-humanize"
)
Expand All @@ -15,13 +13,3 @@ func GetMemStats() string {
runtime.ReadMemStats(&memstats)
return fmt.Sprintf("Alloc: %s, Sys: %s, GC: %d, PauseTotalNs: %dns", humanize.Bytes(memstats.Alloc), humanize.Bytes(memstats.Sys), memstats.NumGC, memstats.PauseTotalNs)
}

func Tic(s string) time.Time {
log.Println("START:", s)
return time.Now()
}

func Toc(start time.Time) {
end := time.Now()
log.Println("END: ElapsedTime in seconds:", end.Sub(start))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These may be actually occasionally useful for profiling?

BTW I didn't even know about the existence of this internal/util/profile.go until now (and I find it rather nice). (And BTW also I didn't know about the existence of the memusage command.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big deal to write two lines when we need to profile something. For now, I propose removing redundant code that is not used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly would we achieve by removing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing unnecessary functions will allow refactoring the util package into something more meaningful with a better name.

The package name util is considered a bad package name according to https://go.dev/blog/package-names#bad-package-names.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactoring the util package into something more meaningful with a better name.

Like what?

Copy link
Collaborator

@JoeKar JoeKar Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package name util is considered a bad package name according to https://go.dev/blog/package-names#bad-package-names.

So it's the usual ideal world example which would have been nice in the moment it has been respected from the beginning. But unfortunately the world isn't ideal, it hasn't been considered from the beginning and thus util is grown historically by throwing everything into it which doesn't fit into the other base packages.
I wouldn't say that we're against such a cleanup process, but currently we've bigger construction sites at other places.

Like what?

As said by @dmaluka or at least how I interpret it:
If you have a much better suggestion, please go ahead.
But remember, especially with the lua.go in util we most probably face problems with plugin interfaces.

17 changes: 0 additions & 17 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,6 @@ func IsNonWordChar(r rune) bool {
return !IsWordChar(r)
}

// IsUpperWordChar returns whether or not a rune is an 'upper word character'
// Upper word characters are defined as numbers, upper-case letters or sub-word delimiters
func IsUpperWordChar(r rune) bool {
return IsUpperAlphanumeric(r) || IsSubwordDelimiter(r)
}

// IsLowerWordChar returns whether or not a rune is a 'lower word character'
// Lower word characters are defined as numbers, lower-case letters or sub-word delimiters
func IsLowerWordChar(r rune) bool {
return IsLowerAlphanumeric(r) || IsSubwordDelimiter(r)
}
alexandear marked this conversation as resolved.
Show resolved Hide resolved

// IsSubwordDelimiter returns whether or not a rune is a 'sub-word delimiter character'
// i.e. is considered a part of the word and is used as a delimiter between sub-words of the word.
// For now the only sub-word delimiter character is '_'.
Expand Down Expand Up @@ -510,11 +498,6 @@ func IsAutocomplete(c rune) bool {
return c == '.' || IsWordChar(c)
}

// ParseSpecial replaces escaped ts with '\t'.
func ParseSpecial(s string) string {
return strings.ReplaceAll(s, "\\t", "\t")
}

// String converts a byte array to a string (for lua plugins)
func String(s []byte) string {
return string(s)
Expand Down
13 changes: 0 additions & 13 deletions pkg/highlight/highlighter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ func runePos(p int, str []byte) int {
return CharacterCount(str[:p])
}

func combineLineMatch(src, dst LineMatch) LineMatch {
for k, v := range src {
if g, ok := dst[k]; ok {
if g == 0 {
dst[k] = v
}
} else {
dst[k] = v
}
}
return dst
}

// A State represents the region at the end of a line
type State *region

Expand Down