Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions pkg/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ type fileLoader struct {
comparePathsOptions tspath.ComparePathsOptions
supportedExtensions []string

filesParser *filesParser
rootTasks []*parseTask
includeProcessor *includeProcessor
filesParser *filesParser
rootTasks []*parseTask

totalFileCount atomic.Int32
libFileCount atomic.Int32
Expand Down Expand Up @@ -101,7 +100,6 @@ func processAllProgramFiles(
},
rootTasks: make([]*parseTask, 0, len(rootFiles)+len(compilerOptions.Lib)),
supportedExtensions: core.Flatten(tsoptions.GetSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, supportedExtensions)),
includeProcessor: &includeProcessor{},
}
loader.addProjectReferenceTasks(singleThreaded)
loader.resolver = module.NewResolver(loader.projectReferenceFileMapper.host, compilerOptions, opts.TypingsLocation, opts.ProjectName)
Expand Down Expand Up @@ -363,7 +361,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
includeReason: includeReason,
}, nil)
} else {
p.includeProcessor.addProcessingDiagnostic(&processingDiagnostic{
t.processingDiagnostics = append(t.processingDiagnostics, &processingDiagnostic{
kind: processingDiagnosticKindUnknownReference,
data: includeReason,
})
Expand Down
26 changes: 14 additions & 12 deletions pkg/compiler/filesparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (t *parseTask) load(loader *fileLoader) {
includeReason: includeReason,
}, libFile)
} else {
loader.includeProcessor.addProcessingDiagnostic(&processingDiagnostic{
t.processingDiagnostics = append(t.processingDiagnostics, &processingDiagnostic{
kind: processingDiagnosticKindUnknownReference,
data: includeReason,
})
Expand Down Expand Up @@ -268,7 +268,9 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
tasksSeenByNameIgnoreCase = make(map[string]*parseTask, totalFileCount)
}

loader.includeProcessor.fileIncludeReasons = make(map[tspath.Path][]*FileIncludeReason, totalFileCount)
includeProcessor := &includeProcessor{
fileIncludeReasons: make(map[tspath.Path][]*FileIncludeReason, totalFileCount),
}
var outputFileToProjectReferenceSource map[tspath.Path]string
if !loader.opts.canUseProjectReferenceSource() {
outputFileToProjectReferenceSource = make(map[tspath.Path]string, totalFileCount)
Expand All @@ -292,7 +294,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
if task.loadedTask != nil {
task = task.loadedTask
}
w.addIncludeReason(loader, task, includeReason)
w.addIncludeReason(includeProcessor, task, includeReason)
}
data, _ := w.taskDataByPath.Load(task.path)
if !task.loaded {
Expand All @@ -306,7 +308,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
checkedAbsolutePath := tspath.GetNormalizedAbsolutePathWithoutRoot(checkedName, loader.comparePathsOptions.CurrentDirectory)
inputAbsolutePath := tspath.GetNormalizedAbsolutePathWithoutRoot(task.normalizedFilePath, loader.comparePathsOptions.CurrentDirectory)
if checkedAbsolutePath != inputAbsolutePath {
loader.includeProcessor.addProcessingDiagnosticsForFileCasing(task.path, checkedName, task.normalizedFilePath, includeReason)
includeProcessor.addProcessingDiagnosticsForFileCasing(task.path, checkedName, task.normalizedFilePath, includeReason)
}
}
continue
Expand All @@ -317,7 +319,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
if tasksSeenByNameIgnoreCase != nil {
pathLowerCase := tspath.ToFileNameLowerCase(string(task.path))
if taskByIgnoreCase, ok := tasksSeenByNameIgnoreCase[pathLowerCase]; ok {
loader.includeProcessor.addProcessingDiagnosticsForFileCasing(taskByIgnoreCase.path, taskByIgnoreCase.normalizedFilePath, task.normalizedFilePath, includeReason)
includeProcessor.addProcessingDiagnosticsForFileCasing(taskByIgnoreCase.path, taskByIgnoreCase.normalizedFilePath, task.normalizedFilePath, includeReason)
} else {
tasksSeenByNameIgnoreCase[pathLowerCase] = task
}
Expand Down Expand Up @@ -351,7 +353,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
path := task.path

if len(task.processingDiagnostics) > 0 {
loader.includeProcessor.processingDiagnostics = append(loader.includeProcessor.processingDiagnostics, task.processingDiagnostics...)
includeProcessor.processingDiagnostics = append(includeProcessor.processingDiagnostics, task.processingDiagnostics...)
}

if file == nil {
Expand Down Expand Up @@ -420,19 +422,19 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules,
libFiles: libFilesMap,
missingFiles: missingFiles,
includeProcessor: loader.includeProcessor,
includeProcessor: includeProcessor,
outputFileToProjectReferenceSource: outputFileToProjectReferenceSource,
}
}

func (w *filesParser) addIncludeReason(loader *fileLoader, task *parseTask, reason *FileIncludeReason) {
func (w *filesParser) addIncludeReason(includeProcessor *includeProcessor, task *parseTask, reason *FileIncludeReason) {
if task.redirectedParseTask != nil {
w.addIncludeReason(loader, task.redirectedParseTask, reason)
w.addIncludeReason(includeProcessor, task.redirectedParseTask, reason)
} else if task.loaded {
if existing, ok := loader.includeProcessor.fileIncludeReasons[task.path]; ok {
loader.includeProcessor.fileIncludeReasons[task.path] = append(existing, reason)
if existing, ok := includeProcessor.fileIncludeReasons[task.path]; ok {
includeProcessor.fileIncludeReasons[task.path] = append(existing, reason)
} else {
loader.includeProcessor.fileIncludeReasons[task.path] = []*FileIncludeReason{reason}
includeProcessor.fileIncludeReasons[task.path] = []*FileIncludeReason{reason}
}
}
}
126 changes: 126 additions & 0 deletions pkg/lsp/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package lsp

import (
"fmt"
"sync"

"github.com/buke/typescript-go-internal/pkg/lsp/lsproto"
"github.com/buke/typescript-go-internal/pkg/project/logging"
)

var _ logging.Logger = (*logger)(nil)

type logger struct {
server *Server
mu sync.Mutex
verbose bool
}

func newLogger(server *Server) *logger {
return &logger{
server: server,
}
}

func (l *logger) sendLogMessage(msgType lsproto.MessageType, message string) {
if l == nil {
return
}

if !l.server.initStarted.Load() {
fmt.Fprintln(l.server.stderr, message)
return
}

notification := lsproto.WindowLogMessageInfo.NewNotificationMessage(&lsproto.LogMessageParams{
Type: msgType,
Message: message,
})
l.server.outgoingQueue <- notification.Message()
}

func (l *logger) Log(msg ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeLog, fmt.Sprint(msg...))
}

func (l *logger) Logf(format string, args ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeLog, fmt.Sprintf(format, args...))
}

func (l *logger) Verbose() logging.Logger {
if l == nil {
return nil
}
l.mu.Lock()
defer l.mu.Unlock()
if !l.verbose {
return nil
}
return l
}

func (l *logger) IsVerbose() bool {
if l == nil {
return false
}
l.mu.Lock()
defer l.mu.Unlock()
return l.verbose
}

func (l *logger) SetVerbose(verbose bool) {
if l == nil {
return
}
l.mu.Lock()
defer l.mu.Unlock()
l.verbose = verbose
}

func (l *logger) Error(msg ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeError, fmt.Sprint(msg...))
}

func (l *logger) Errorf(format string, args ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeError, fmt.Sprintf(format, args...))
}

func (l *logger) Warn(msg ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeWarning, fmt.Sprint(msg...))
}

func (l *logger) Warnf(format string, args ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeWarning, fmt.Sprintf(format, args...))
}

func (l *logger) Info(msg ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeInfo, fmt.Sprint(msg...))
}

func (l *logger) Infof(format string, args ...any) {
if l == nil {
return
}
l.sendLogMessage(lsproto.MessageTypeInfo, fmt.Sprintf(format, args...))
}
2 changes: 1 addition & 1 deletion pkg/lsp/lsproto/_generate/fetchModel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const __dirname = path.dirname(__filename);
const metaModelPath = path.join(__dirname, "metaModel.json");
const metaModelSchemaPath = path.join(__dirname, "metaModelSchema.mts");

const hash = "dadd73f7fc283b4d0adb602adadcf4be16ef3a7b";
const hash = "2abd2d977aa36e8c6b242ff048bdbf5df71e3088";

const metaModelURL = `https://raw.githubusercontent.com/microsoft/vscode-languageserver-node/${hash}/protocol/metaModel.json`;
const metaModelSchemaURL = `https://raw.githubusercontent.com/microsoft/vscode-languageserver-node/${hash}/tools/src/metaModel.ts`;
Expand Down
20 changes: 20 additions & 0 deletions pkg/lsp/lsproto/_generate/metaModelSchema.mts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ export type Request = {
* the property contains the deprecation message.
*/
deprecated?: string;

/**
* The client capability property path if any.
*/
clientCapability?: string;

/**
* The server capability property path if any.
*/
serverCapability?: string;
};

/**
Expand Down Expand Up @@ -269,6 +279,16 @@ export type Notification = {
* the property contains the deprecation message.
*/
deprecated?: string;

/**
* The client capability property path if any.
*/
clientCapability?: string;

/**
* The server capability property path if any.
*/
serverCapability?: string;
};

/**
Expand Down
Loading