Skip to content

Commit 80eb6f3

Browse files
committed
removed no more used functions
1 parent f8b79ea commit 80eb6f3

File tree

2 files changed

+3
-235
lines changed

2 files changed

+3
-235
lines changed

Diff for: handler/builder.go

-175
Original file line numberDiff line numberDiff line change
@@ -101,178 +101,3 @@ func generateBuildEnvironment(sketchDir *paths.Path, fqbn string) (*paths.Path,
101101
log.Println("arduino-cli output:", cmdOutput)
102102
return res.BuilderResult.BuildPath, nil
103103
}
104-
105-
func filterErrorsAndWarnings(cppCode []byte) string {
106-
var sb strings.Builder
107-
scanner := bufio.NewScanner(bytes.NewReader(cppCode))
108-
for scanner.Scan() {
109-
lineStr := scanner.Text()
110-
if !(strings.HasPrefix(lineStr, "ERROR:") || strings.HasPrefix(lineStr, "WARNING:")) {
111-
sb.WriteString(lineStr)
112-
sb.WriteRune('\n')
113-
}
114-
}
115-
return sb.String()
116-
}
117-
118-
func copyIno2Cpp(inoCode string, cppPath string) (cppCode []byte, err error) {
119-
inoPath := strings.TrimSuffix(cppPath, ".cpp")
120-
filePrefix := "#include <Arduino.h>\n#line 1 \"" + inoPath + "\"\n"
121-
cppCode = []byte(filePrefix + inoCode)
122-
err = ioutil.WriteFile(cppPath, cppCode, 0600)
123-
if err != nil {
124-
err = errors.Wrap(err, "Error while writing target file to temporary directory.")
125-
return
126-
}
127-
if enableLogging {
128-
log.Println("Target file written to", cppPath)
129-
}
130-
return
131-
}
132-
133-
func printCompileFlags(buildProps *properties.Map, printer *Printer, fqbn string) {
134-
if strings.Contains(fqbn, ":avr:") {
135-
printer.Println("--target=avr")
136-
} else if strings.Contains(fqbn, ":sam:") {
137-
printer.Println("--target=arm-none-eabi")
138-
}
139-
cppFlags := buildProps.ExpandPropsInString(buildProps.Get("compiler.cpp.flags"))
140-
printer.Println(splitFlags(cppFlags))
141-
mcu := buildProps.ExpandPropsInString(buildProps.Get("build.mcu"))
142-
if strings.Contains(fqbn, ":avr:") {
143-
printer.Println("-mmcu=", mcu)
144-
} else if strings.Contains(fqbn, ":sam:") {
145-
printer.Println("-mcpu=", mcu)
146-
}
147-
fcpu := buildProps.ExpandPropsInString(buildProps.Get("build.f_cpu"))
148-
printer.Println("-DF_CPU=", fcpu)
149-
ideVersion := buildProps.ExpandPropsInString(buildProps.Get("runtime.ide.version"))
150-
printer.Println("-DARDUINO=", ideVersion)
151-
board := buildProps.ExpandPropsInString(buildProps.Get("build.board"))
152-
printer.Println("-DARDUINO_", board)
153-
arch := buildProps.ExpandPropsInString(buildProps.Get("build.arch"))
154-
printer.Println("-DARDUINO_ARCH_", arch)
155-
if strings.Contains(fqbn, ":sam:") {
156-
libSamFlags := buildProps.ExpandPropsInString(buildProps.Get("compiler.libsam.c.flags"))
157-
printer.Println(splitFlags(libSamFlags))
158-
}
159-
extraFlags := buildProps.ExpandPropsInString(buildProps.Get("build.extra_flags"))
160-
printer.Println(splitFlags(extraFlags))
161-
corePath := buildProps.ExpandPropsInString(buildProps.Get("build.core.path"))
162-
printer.Println("-I", corePath)
163-
variantPath := buildProps.ExpandPropsInString(buildProps.Get("build.variant.path"))
164-
printer.Println("-I", variantPath)
165-
if strings.Contains(fqbn, ":avr:") {
166-
avrgccPath := buildProps.ExpandPropsInString(buildProps.Get("runtime.tools.avr-gcc.path"))
167-
printer.Println("-I", filepath.Join(avrgccPath, "avr", "include"))
168-
}
169-
170-
printLibraryPaths(corePath, printer)
171-
}
172-
173-
func printLibraryPaths(basePath string, printer *Printer) {
174-
parentDir := filepath.Dir(basePath)
175-
if strings.HasSuffix(parentDir, string(filepath.Separator)) || strings.HasSuffix(parentDir, ".") {
176-
return
177-
}
178-
libsDir := filepath.Join(parentDir, "libraries")
179-
if libraries, err := ioutil.ReadDir(libsDir); err == nil {
180-
for _, libInfo := range libraries {
181-
if libInfo.IsDir() {
182-
srcDir := filepath.Join(libsDir, libInfo.Name(), "src")
183-
if srcInfo, err := os.Stat(srcDir); err == nil && srcInfo.IsDir() {
184-
printer.Println("-I", srcDir)
185-
} else {
186-
printer.Println("-I", filepath.Join(libsDir, libInfo.Name()))
187-
}
188-
}
189-
}
190-
}
191-
printLibraryPaths(parentDir, printer)
192-
}
193-
194-
// Printer prints to a Writer and stores the first error.
195-
type Printer struct {
196-
Writer *bufio.Writer
197-
Err error
198-
}
199-
200-
// Println prints the given strings followed by a line break.
201-
func (printer *Printer) Println(text ...string) {
202-
totalLen := 0
203-
for i := range text {
204-
if len(text[i]) > 0 {
205-
_, err := printer.Writer.WriteString(text[i])
206-
if err != nil && printer.Err == nil {
207-
printer.Err = err
208-
}
209-
totalLen += len(text[i])
210-
}
211-
}
212-
if totalLen > 0 {
213-
_, err := printer.Writer.WriteString("\n")
214-
if err != nil && printer.Err == nil {
215-
printer.Err = err
216-
}
217-
}
218-
}
219-
220-
// Flush flushes the underlying writer.
221-
func (printer *Printer) Flush() {
222-
err := printer.Writer.Flush()
223-
if err != nil && printer.Err == nil {
224-
printer.Err = err
225-
}
226-
}
227-
228-
func splitFlags(flags string) string {
229-
flagsBytes := []byte(flags)
230-
result := make([]byte, len(flagsBytes))
231-
inSingleQuotes := false
232-
inDoubleQuotes := false
233-
for i, b := range flagsBytes {
234-
if b == '\'' && !inDoubleQuotes {
235-
inSingleQuotes = !inSingleQuotes
236-
}
237-
if b == '"' && !inSingleQuotes {
238-
inDoubleQuotes = !inDoubleQuotes
239-
}
240-
if b == ' ' && !inSingleQuotes && !inDoubleQuotes {
241-
result[i] = '\n'
242-
} else {
243-
result[i] = b
244-
}
245-
}
246-
return string(result)
247-
}
248-
249-
func logCommandErr(command *exec.Cmd, stdout []byte, err error, filter func(string) string) error {
250-
message := ""
251-
log.Println("Command error:", command.Args, err)
252-
if len(stdout) > 0 {
253-
stdoutStr := string(stdout)
254-
log.Println("------------------------------BEGIN STDOUT\n", stdoutStr, "------------------------------END STDOUT")
255-
message += filter(stdoutStr)
256-
}
257-
if exitErr, ok := err.(*exec.ExitError); ok {
258-
stderr := exitErr.Stderr
259-
if len(stderr) > 0 {
260-
stderrStr := string(stderr)
261-
log.Println("------------------------------BEGIN STDERR\n", stderrStr, "------------------------------END STDERR")
262-
message += filter(stderrStr)
263-
}
264-
}
265-
if len(message) == 0 {
266-
return err
267-
}
268-
return errors.New(message)
269-
}
270-
271-
func errMsgFilter(tempDir string) func(string) string {
272-
if !strings.HasSuffix(tempDir, string(filepath.Separator)) {
273-
tempDir += string(filepath.Separator)
274-
}
275-
return func(s string) string {
276-
return strings.ReplaceAll(s, tempDir, "")
277-
}
278-
}

Diff for: handler/handler.go

+3-60
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type CLangdStarter func() (stdin io.WriteCloser, stdout io.ReadCloser, stderr io
4141
// NewInoHandler creates and configures an InoHandler.
4242
func NewInoHandler(stdio io.ReadWriteCloser, board lsp.Board) *InoHandler {
4343
handler := &InoHandler{
44-
//data: map[lsp.DocumentURI]*FileData{},
4544
trackedFiles: map[lsp.DocumentURI]*lsp.TextDocumentItem{},
4645
config: lsp.BoardConfig{
4746
SelectedBoard: board,
@@ -225,9 +224,9 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
225224
case *lsp.DidCloseTextDocumentParams: // "textDocument/didClose":
226225
log.Printf("--X " + req.Method)
227226
return nil, nil
228-
uri = p.TextDocument.URI
229-
err = handler.sketchToBuildPathTextDocumentIdentifier(&p.TextDocument)
230-
handler.deleteFileData(uri)
227+
// uri = p.TextDocument.URI
228+
// err = handler.sketchToBuildPathTextDocumentIdentifier(&p.TextDocument)
229+
// handler.deleteFileData(uri)
231230
// case "textDocument/signatureHelp":
232231
// fallthrough
233232
// case "textDocument/definition":
@@ -524,62 +523,6 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
524523
return cppReq, err
525524
}
526525

527-
func (handler *InoHandler) updateFileData(ctx context.Context, data *FileData, change *lsp.TextDocumentContentChangeEvent) (err error) {
528-
rang := change.Range
529-
if rang == nil || rang.Start.Line != rang.End.Line {
530-
// Update the source text and regenerate the cpp code
531-
var newSourceText string
532-
if rang == nil {
533-
newSourceText = change.Text
534-
} else {
535-
newSourceText, err = textutils.ApplyTextChange(data.sourceText, *rang, change.Text)
536-
if err != nil {
537-
return err
538-
}
539-
}
540-
targetBytes, err := updateCpp([]byte(newSourceText), data.sourceURI.Unbox(), handler.config.SelectedBoard.Fqbn, false, data.targetURI.Unbox())
541-
if err != nil {
542-
if rang == nil {
543-
// Fallback: use the source text unchanged
544-
targetBytes, err = copyIno2Cpp(newSourceText, data.targetURI.Unbox())
545-
if err != nil {
546-
return err
547-
}
548-
} else {
549-
// Fallback: try to apply a multi-line update
550-
data.sourceText = newSourceText
551-
//data.sourceMap.Update(rang.End.Line-rang.Start.Line, rang.Start.Line, change.Text)
552-
*rang = data.sourceMap.InoToCppLSPRange(data.sourceURI, *rang)
553-
return nil
554-
}
555-
}
556-
557-
data.sourceText = newSourceText
558-
data.sourceMap = sourcemapper.CreateInoMapper(targetBytes)
559-
560-
change.Text = string(targetBytes)
561-
change.Range = nil
562-
change.RangeLength = 0
563-
} else {
564-
// Apply an update to a single line both to the source and the target text
565-
data.sourceText, err = textutils.ApplyTextChange(data.sourceText, *rang, change.Text)
566-
if err != nil {
567-
return err
568-
}
569-
//data.sourceMap.Update(0, rang.Start.Line, change.Text)
570-
571-
*rang = data.sourceMap.InoToCppLSPRange(data.sourceURI, *rang)
572-
}
573-
return nil
574-
}
575-
576-
func (handler *InoHandler) deleteFileData(sourceURI lsp.DocumentURI) {
577-
// if data, ok := handler.data[sourceURI]; ok {
578-
// delete(handler.data, data.sourceURI)
579-
// delete(handler.data, data.targetURI)
580-
// }
581-
}
582-
583526
func (handler *InoHandler) handleError(ctx context.Context, err error) error {
584527
errorStr := err.Error()
585528
var message string

0 commit comments

Comments
 (0)