Skip to content

Commit

Permalink
Update semantic.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Aug 24, 2024
1 parent f5059d4 commit 177b9ed
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions packages/typescript/lib/plugins/semantic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,58 +244,57 @@ export function create(

let formattingOptions: FormattingOptions | undefined;

if (created) {
if (created.setPreferences && context.env.getConfiguration) {
if (created?.setPreferences && context.env.getConfiguration) {

updatePreferences();
context.env.onDidChangeConfiguration?.(updatePreferences);
updatePreferences();
context.env.onDidChangeConfiguration?.(updatePreferences);

async function updatePreferences() {
const preferences = await context.env.getConfiguration?.<ts.UserPreferences>('typescript.preferences');
if (preferences) {
created!.setPreferences?.(preferences);
}
async function updatePreferences() {
const preferences = await context.env.getConfiguration?.<ts.UserPreferences>('typescript.preferences');
if (preferences) {
created!.setPreferences?.(preferences);
}
}
if (created.projectUpdated) {
}

const sourceScriptNames = new Set<string>();
const normalizeFileName = sys.useCaseSensitiveFileNames
? (id: string) => id
: (id: string) => id.toLowerCase();
if (created?.projectUpdated) {

updateSourceScriptFileNames();
const sourceScriptNames = new Set<string>();
const normalizeFileName = sys.useCaseSensitiveFileNames
? (id: string) => id
: (id: string) => id.toLowerCase();

context.env.onDidChangeWatchedFiles?.(params => {
const someFileCreateOrDeiete = params.changes.some(change => change.type !== 2 satisfies typeof FileChangeType.Changed);
if (someFileCreateOrDeiete) {
updateSourceScriptFileNames();
}
for (const change of params.changes) {
const fileName = uriConverter.asFileName(URI.parse(change.uri));
if (sourceScriptNames.has(normalizeFileName(fileName))) {
created.projectUpdated?.(languageServiceHost.getCurrentDirectory());
}
updateSourceScriptFileNames();

context.env.onDidChangeWatchedFiles?.(params => {
const someFileCreateOrDeiete = params.changes.some(change => change.type !== 2 satisfies typeof FileChangeType.Changed);
if (someFileCreateOrDeiete) {
updateSourceScriptFileNames();
}
for (const change of params.changes) {
const fileName = uriConverter.asFileName(URI.parse(change.uri));
if (sourceScriptNames.has(normalizeFileName(fileName))) {
created.projectUpdated?.(languageServiceHost.getCurrentDirectory());
}
});

function updateSourceScriptFileNames() {
sourceScriptNames.clear();
for (const fileName of languageServiceHost.getScriptFileNames()) {
const maybeEmbeddedUri = ctx.fileNameToUri(fileName);
const decoded = context.decodeEmbeddedDocumentUri(maybeEmbeddedUri);
const uri = decoded ? decoded[0] : maybeEmbeddedUri;
const sourceScript = context.language.scripts.get(uri);
if (sourceScript?.generated) {
const tsCode = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
if (tsCode) {
sourceScriptNames.add(normalizeFileName(fileName));
}
}
else if (sourceScript) {
}
});

function updateSourceScriptFileNames() {
sourceScriptNames.clear();
for (const fileName of languageServiceHost.getScriptFileNames()) {
const maybeEmbeddedUri = ctx.fileNameToUri(fileName);
const decoded = context.decodeEmbeddedDocumentUri(maybeEmbeddedUri);
const uri = decoded ? decoded[0] : maybeEmbeddedUri;
const sourceScript = context.language.scripts.get(uri);
if (sourceScript?.generated) {
const tsCode = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
if (tsCode) {
sourceScriptNames.add(normalizeFileName(fileName));
}
}
else if (sourceScript) {
sourceScriptNames.add(normalizeFileName(fileName));
}
}
}
}
Expand Down

0 comments on commit 177b9ed

Please sign in to comment.