Skip to content
Open
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
5 changes: 5 additions & 0 deletions _extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
{
"title": "TypeScript Native Preview",
"properties": {
"typescript.native-preview.customConfigFileName": {
"type": "string",
"description": "Custom config file name to use, before defaulting to tsconfig.json/jsconfig.json.",
"tags": ["experimental"]
},
"typescript.native-preview.trace.server": {
"type": "string",
"enum": [
Expand Down
8 changes: 7 additions & 1 deletion _extension/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class Client {
const config = vscode.workspace.getConfiguration("typescript.native-preview");
const pprofDir = config.get<string>("pprofDir");
const pprofArgs = pprofDir ? ["--pprofDir", pprofDir] : [];
const customConfigFileName = config.get<string>("customConfigFileName") ?? "";

const serverOptions: ServerOptions = {
run: {
Expand All @@ -112,7 +113,12 @@ export class Client {
"typescript.native-preview",
"typescript.native-preview-lsp",
serverOptions,
this.clientOptions,
{
...this.clientOptions,
initializationOptions: {
customConfigFileName,
},
},
);

this.outputChannel.appendLine(`Starting language server...`);
Expand Down
5 changes: 3 additions & 2 deletions _extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export async function activate(context: vscode.ExtensionContext) {
registerCommands(context, client, output, traceOutput);

context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration("typescript.experimental.useTsgo")) {
if (event.affectsConfiguration("typescript.experimental.useTsgo") ||
event.affectsConfiguration("typescript.native-preview.customConfigFileName")) {
// Delay because the command to change the config setting will restart
// the extension host, so no need to show a message
setTimeout(async () => {
const selected = await vscode.window.showInformationMessage("TypeScript Native Preview setting has changed. Restart extensions to apply changes.", "Restart Extensions");
const selected = await vscode.window.showInformationMessage("TypeScript Native Preview settings have changed. Restart extensions to apply changes.", "Restart Extensions");
if (selected) {
vscode.commands.executeCommand("workbench.action.restartExtensionHost");
}
Expand Down
25 changes: 18 additions & 7 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,26 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali
s.watchEnabled = true
}

// Read customConfigFileName from initializationOptions if provided
var customConfigFileName string
if init := s.initializeParams; init != nil && init.InitializationOptions != nil {
if m, ok := (*init.InitializationOptions).(map[string]any); ok {
if v, ok := m["customConfigFileName"].(string); ok {
customConfigFileName = v
}
}
}

s.session = project.NewSession(&project.SessionInit{
Options: &project.SessionOptions{
CurrentDirectory: s.cwd,
DefaultLibraryPath: s.defaultLibraryPath,
TypingsLocation: s.typingsLocation,
PositionEncoding: s.positionEncoding,
WatchEnabled: s.watchEnabled,
LoggingEnabled: true,
DebounceDelay: 500 * time.Millisecond,
CurrentDirectory: s.cwd,
DefaultLibraryPath: s.defaultLibraryPath,
TypingsLocation: s.typingsLocation,
PositionEncoding: s.positionEncoding,
WatchEnabled: s.watchEnabled,
LoggingEnabled: true,
DebounceDelay: 500 * time.Millisecond,
CustomConfigFileName: customConfigFileName,
},
FS: s.fs,
Logger: s.logger,
Expand Down
22 changes: 21 additions & 1 deletion internal/project/configfileregistrybuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,27 @@ func (c *configFileRegistryBuilder) handleConfigChange(entry *dirty.SyncMapEntry

func (c *configFileRegistryBuilder) computeConfigFileName(fileName string, skipSearchInDirectoryOfFile bool, logger *logging.LogTree) string {
searchPath := tspath.GetDirectoryPath(fileName)
result, _ := tspath.ForEachAncestorDirectory(searchPath, func(directory string) (result string, stop bool) {
skipSearchInDirectoryOfFileForCustomConfig := skipSearchInDirectoryOfFile
var result string
// If custom config file is provided, search for it in directory of file and its ancestors first.
// If a custom config file is provided and not found, default to tsconfig.json/jsconfig.json.
if c.sessionOptions.CustomConfigFileName != "" {
result, _ = tspath.ForEachAncestorDirectory(searchPath, func(directory string) (result string, stop bool) {
customConfigFilePath := tspath.CombinePaths(directory, c.sessionOptions.CustomConfigFileName)
if !skipSearchInDirectoryOfFileForCustomConfig && c.FS().FileExists(customConfigFilePath) {
return customConfigFilePath, true
}
skipSearchInDirectoryOfFileForCustomConfig = false
return "", false
})
}

if result != "" {
logger.Logf("computeConfigFileName:: File: %s:: Result: %s", fileName, result)
return result
}

result, _ = tspath.ForEachAncestorDirectory(searchPath, func(directory string) (result string, stop bool) {
tsconfigPath := tspath.CombinePaths(directory, "tsconfig.json")
if !skipSearchInDirectoryOfFile && c.FS().FileExists(tsconfigPath) {
return tsconfigPath, true
Expand Down
1 change: 1 addition & 0 deletions internal/project/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type SessionOptions struct {
WatchEnabled bool
LoggingEnabled bool
DebounceDelay time.Duration
CustomConfigFileName string
}

type SessionInit struct {
Expand Down
Loading